Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
embedded if statements
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
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!
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to identify controls embedded within WinListView cells Devesh Thakur 5 2,746 04-19-2018, 10:56 AM
Last Post: Devesh Thakur
  Embedded Text on webpage srach84 1 2,722 07-28-2014, 07:35 AM
Last Post: Ankur
  Retrieving default value from embedded webedit from webtable indranilgoswamimcb 1 3,119 01-12-2012, 02:47 PM
Last Post: sshukla12
  For loop after couple of If then else statements Mala 4 5,168 02-16-2011, 06:37 AM
Last Post: Mala
  Adding Conditional Statements in Keyword driven automation framework prachisharma76 0 3,822 09-14-2010, 11:00 AM
Last Post: prachisharma76

Forum Jump:


Users browsing this thread: 3 Guest(s)