Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
seniors Please help---New to QTP and forum---Datatable question
#1
Not Solved
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
Reply
#2
Not Solved
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
Reply
#3
Not Solved
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  The most reputed and oldest Q & A forum on HP Unified Functional Testing tool (earlie qtptouft 0 1,346 09-30-2015, 01:52 PM
Last Post: qtptouft
  Hello All -Nice forum to start learning QTP. Few questions QTP.learning 0 1,896 05-18-2014, 04:10 PM
Last Post: QTP.learning
  Question about QTP tutorial - Yousuf 1 2,645 11-15-2013, 09:25 PM
Last Post: Yousuf
  qtp interview question raaj123 2 2,421 01-21-2013, 03:12 PM
Last Post: Ankesh
  Datatable add and datatable import sheet wheelercha 4 33,634 06-14-2012, 04:53 PM
Last Post: Arul

Forum Jump:


Users browsing this thread: 1 Guest(s)