Micro Focus QTP (UFT) Forums
seniors Please help---New to QTP and forum---Datatable question - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: seniors Please help---New to QTP and forum---Datatable question (/Thread-seniors-Please-help-New-to-QTP-and-forum-Datatable-question)



seniors Please help---New to QTP and forum---Datatable question - tarry65 - 05-27-2009

I am picking the value-----from datatable
value---0000123_200908_201208.xml

I want three things to be done---
1.check first seven charcters are seven before _.
2.Check date format is yyyymm .
3.check first date > second date.

Expert and senior people Please help me with code if possible


RE: seniors Please help---New to QTP and forum---Datatable question - stephenlb4u - 05-28-2009

hi Tarry,

Use the below script
Code:
Text= DataTable("A", dtGlobalSheet)

Dim sText


'Splitting the given string with the delimiter _ and saving it in the array called sText

sText = Split(Text,"_")

'Displaying the length of character before _


Msgbox "First Seven Text before _ is:  " &sText(0)


If  len( sText(0)) >6 or len( sText(0)) <6Then

Msgbox"Lenght of character before _ is 6"

else

Msgbox"Lenght of character before _ is not equal to 6"

End If



'Displaying the lenght of character after and before _



Msgbox "Second Six Character (yyyymm) after and before _ is: " &sText(1)


'i dont think we can validate the second condition but any how we can check weather the month is valid or not

'Splliting the date as YYYY and MM using mid function

mnth = Mid (sText(1),5)

If mnth < 0 or mnth > 12 Then

msgbox "The date format is not valid"

else

yr = Mid (sText(1),1,4)

msgbox "Date is "&MonthName(mnth)&yr

End If

' Comparastion btw two date


Msgbox "Third Six Character (yyyymm) after 2nd _ is: " &sText(2)

If sText(2) > sText(1) Then

    Msgbox "Second date is Greater than the First"

Else

   Msgbox "Second date is Not Greater than the First"
  
End If

Thanks
Stephen


RE: seniors Please help---New to QTP and forum---Datatable question - Jackomcnabb - 05-28-2009

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