05-28-2009, 05:58 PM
This is very crude I left all the comments in and invalid tests for you to see how i've tested the code.
Code:
'test valid input
InValue="0000123_200908_201208.xml"
'test dates same
'InValue="0000123_200908_200908.xml"
'test invalid Year
'InValue="0000123_200908_200808.xml"
'test same year invalid month
'InValue="0000123_200908_200907.xml"
'test invalid first string legth
'InValue="000123_200908_201207.xml"
'split string to remove .xml
NewInValue=Split(InValue,".")
NewString=NewInValue(0)
'msgbox(NewString)
'load into an array to split the Strings by '_"
splitValues=Split(NewString,"_")
FirstSeven=splitValues(0)
'msgbox(FirstSeven)
FirstDate=splitValues(1)
'msgbox(FirstDate)
SecondDate=(splitValues(2))
'msgbox(SecondDate)
'check the length of the string
LenthFirstSeven=Len(FirstSeven)
'msgbox(LenthFirstSeven)
If LenthFirstSeven = 7 Then
Reporter.ReportEvent micPass, "StringLength", "The String length was "&LenthFirstSeven&""
Else
Reporter.ReportEvent micfail, "StringLength", "The String length was "&LenthFirstSeven&""
End If
FirstYear=left(FirstDate,4)
'msgbox(FirstYear)
Firstmonth=right(FirstDate,2)
'msgbox(firstmonth)
SecondYear=left(SecondDate,4)
'msgbox(SecondYear)
Secondmonth=right(SecondDate,2)
'msgbox(Secondmonth)
If FirstYear > SecondYear Then
Reporter.ReportEvent micfail, "DateCheck", "The First Year Was Greater than the Second Year"
Elseif FirstYear < SecondYear then
Reporter.ReportEvent micPass, "DateCheck", "The First Year Was Less than the Second Year"
Elseif FirstYear = SecondYear then
If Firstmonth > Secondmonth Then
Reporter.ReportEvent micfail, "DateCheck", "The First Year Equal to Second Year, First Month was greater than second month"
ElseIf Firstmonth < Secondmonth Then
Reporter.ReportEvent micPass, "DateCheck", "The First Year Equal to Second Year, First Month was Less than second month"
Else
Reporter.ReportEvent micfail, "DateCheck", "The Dates are the same"
End If
End If