Micro Focus QTP (UFT) Forums
For loop after couple of If then else statements - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: For loop after couple of If then else statements (/Thread-For-loop-after-couple-of-If-then-else-statements)



For loop after couple of If then else statements - Mala - 02-16-2011

Hi
I am trying to use for loop in the middle of the code and is not working. The way I wrote is as follows
[statements to execute - 1st set]
For i = 1 To 3
[statements to execute - 2nd set]
Next
In the above situation the loop is not getting executed at all. 1st set of statements are executed 3 times.
So Changed it to
Dim i
[statements to execute - 1st set]
For i = 1 To 3
[statements to execute - 2nd set]
Next
Now there are 3 sets of "1st statement executes and then the 2nd statement is executed 3 times" (that means 3 times this path).
The 1st statement has 9 blocks of if then end if statements.
Can any one help me here pelase???


RE: For loop after couple of If then else statements - jsknight1969 - 02-16-2011

If your 1set is not suppose to repeat (ie, no for or while loops), maybe your action run properties are set to run "all rows" of your datasheet. even if the datasheet looks blank, it can cause a loop for each row.

Without seeing your actual code, it is difficult to see a reason for this behavior.

Hope this helps.


RE: For loop after couple of If then else statements - Mala - 02-16-2011

Here is the code - Thanks for looking into this!
Code:
Dim i
If Browser("x").Page("y").WebEdit("a").GetROProperty ("Disabled") = False Then
            Reporter.ReportEvent micPass, "a", "a Enabled"
Else
            Reporter.ReportEvent micFail, "a", "a Enabled"
End If
If  Browser("x").Page("y").WebEdit("b"). GetROProperty("Disabled") = False Then
    Reporter.ReportEvent micPass, "b", "b Enabled"
Else
             Reporter.ReportEvent micFail, "b", "b Enabled"
End If
If Browser("x").Page("y").WebEdit("c").GetROProperty("Disabled") = False Then
    Reporter.ReportEvent micPass, "c", "c Enabled"
Else
    Reporter.ReportEvent micFail, "c", "c Enabled"
End If
Browser("x").Page("y").WebEdit("d").GetROProperty("Enabled") = False Then
    Reporter.ReportEvent micPass, "d", "d Disabled"
Else
    Reporter.ReportEvent micFail, "d", "d Disabled"
End If
If Browser("x").Page("y").WebEdit("e").GetROProperty("Disabled") = False Then
    Reporter.ReportEvent micPass, "e", "e Enabled"
Else
    Reporter.ReportEvent micFail, "e", "e Enabled"
End If

For i = 1 To 3
Browser("x").Page("y").WebEdit("a").Set DataTable("a", dtGlobalSheet)
Browser("x").Page("y").WebEdit("a").Set DataTable("b", dtGlobalSheet)
Browser("x").Page("y").WebEdit("a").Set DataTable("c", dtGlobalSheet)
Browser("x").Page("y").WebEdit("a").Set DataTable("d", dtGlobalSheet)
Browser("x").Page("y").WebEdit("a").Set DataTable("e", dtGlobalSheet)
Browser("x").Page("y").WebElement("Search").Click
Next



RE: For loop after couple of If then else statements - jsknight1969 - 02-16-2011

did you check your "Action Call Properties"? You are using datasheets and you are probably set to "run all rows" instead of "one iteration". If you are set to "all rows" you will progressively run more and more iterations as your data sheet grows.

You don't seem to be changing rows on your datasheet. Do you mean for the For loop to only read the same row for values 3 times?

That is the only thing I can see that would cause this behavior. your code looks fine.


RE: For loop after couple of If then else statements - Mala - 02-16-2011

Checked Action Call Properties and here are the results: With one iteration selected - The first row is being executed 3 times and not going to next two rows. If I select from row 1 - 3 - for one cycle, the first row in the data table is getting executed 3 times so 3 iterarions means 9 executions!!!
Not sure where I am going wrong??? Smile)