embedded if statements - folker - 11-03-2011
Hi all, hopefully you can help me with this issue I've been having.
As a background, I'm use to Java and vb.net. I have just got into QTP and VBA to automate some of my regression testing.
Anyway, I have this gigantic for loop but some of the if statements are getting messed up.
Here is the code....
Code: For counter=1 to ubound(tobechanged)
fstr = mid(tobechanged(counter), 1, 3)
mstr=mid(tobechanged(counter), 4, 2)
lStr = mid(tobechanged(counter), 6, 9)
dashSSN=fstr & "-" & mstr &"-"& lstr
If fstr="" Then
msgbox("Reached end of file")
else
Browser("My Page").Page("System Online").Frame("menu2").Link("Search").Click
Browser("Search").Page("Search").WebRadioGroup("rdOption").Select "1"
Browser("Search").Page("Search").Sync
Browser("Search").Page("Search").WebEdit("sub_txtValue1").Set fstr
Browser("Search").Page("Search").WebEdit("sub_txtValue1_2").Set mstr
Browser("Search").Page("Search").WebEdit("sub_txtValue1_3").Set lstr
Browser("Search").Page("Search").WebEdit("sub_txtValue1").Click
Browser("Search").WinObject("Internet Explorer_Server").Type micTab
wait 1
Browser("Search").WinObject("Internet Explorer_Server").Type micTab
Browser("Search").WinObject("Internet Explorer_Server").Type micTab
wait 1
Browser("Search").Page("Search").Link("Submit").Click
'Browser("Search").WinObject("Internet Explorer_Server").Type micTab
Browser("Search").Page("Search").Sync
'Set Obj = Browser("Search").Page("Search").WebTable("WebTable").ChildItem(0, 1, "WebElement", 0)
inSSN =dashSSN
Repository.Value ("Social") = inSSN
'Browser("Search").Page("Search").Link("Social Security Number").Click
If Browser("Search").Page("Search").Link("Social Security Number").Exist(5) then
'iForComments = iForComments & "SSN search successful" & chr(10)
Browser("Search").Page("Search").Link("Social Security Number").Click
wait 2, 500
Browser("My Page").Page("System Online").Frame("menu2").Link("Manage Annuitants").Click
wait 2
Browser("My Page").Page("System Online").Frame("events").Link("Disbursement History").Click
wait 1
'if exists then do
[b]If Browser("My Page").Page("System Online").Frame("main_brow").WebRadioGroup("selectedRow").exist(5) then[/b]
'execute screenshot
Browser("My Page").Page("System Online").Frame("main_brow").WebRadioGroup("selectedRow").Select "#0"
'Desktop.CaptureBitmap Filename, [OverrideExisting]
'captures screenshot by using snagit
Set objShell = CreateObject("WScript.Shell")
Set oSnag = CreateObject("SNAGIT.ImageCapture")
oSnag.IncludeCursor = False
oSnag.OutputImageFile.FileType = 5
oSnag.OutputImageFile.FileNamingMethod = 1
oSnag.OutputImageFile.Directory = "C:\StaleCheckScreenshots\"
oSnag.OutputImageFile.Filename = inSSN
oSnag.EnablePreviewWindow = False
oSnag.AutoScrollOptions.AutoScrollMethod= 1
oSnag.Capture()
Wait (1)
objShell.SendKeys "{ENTER}"
capDone = oSnag.IsCaptureDone
Do Until oSnag.IsCaptureDone
Loop
Set oSnag=Nothing
Set objShell=Nothing
Else
'ForComments = iForComments & "SSN search was not successful. Using the last used SSN" & chr(10)
'oBaseObjectSearch.Close
End If
[b]else
[/b]
b.Cells(counter2, 4).Value=Nocheck
a.Save
b.save
a.Close
Set a = nothing
Set b = nothing
end if
end if
counter2= counter2+1
Next
Basically, if the first row in a webtable doesn't exist, it should execute this part
b.Cells(counter2, 4).Value=Nocheck
a.Save
b.save
a.Close
Set a = nothing
Set b = nothing
However, it doesn't. When this program executes, it simply goes to the next statement and starts at the for statement again..
I've tried this a number of different ways, I tried adding else and end if in different places but I'm not sure how QTP matches which if belongs with which end if.
It should be right before the last end if, but when I place the else and end if there, it says I have a syntax error.
Any help would be greatly appreciated!
RE: embedded if statements - Ankesh - 11-04-2011
Hi folker,
There is a problem with syntax in ur code which is
Code: Do Until oSnag.IsCaptureDone
Loop
Set oSnag=Nothing
Set objShell=Nothing
====================
Below is the correct syntax of do loop...
Code: Do { While | Until } condition
[ statements ]
[ Exit Do ]
[ statements ]
Loop
-or-
Do
[ statements ]
[ Exit Do ]
[ statements ]
Loop { While | Until } condition
Regards,
Ankesh
so ur code should be something like...
Code: Do Until oSnag.IsCaptureDone
Set oSnag=Nothing
Set objShell=Nothing
Loop
I hope this will work.
|