Increment a variable by 1?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2010
01:12 AM
08-03-2010
01:12 AM
Increment a variable by 1?
I have a loop I only want to run a maximum of 10 times. How do I get a variable to increase everytime the loop runs?
As far as I can see this should work but I obviously have some syntax incorrect somewhere.
if expectFailure then
dim i
i = 0
do
aqUtils.Delay 100
set obj = browser.NativeWebObject.Find("class", "confirmboxcont")
set i = i + 1
loop until obj.Exists or i >= 10
end if
As far as I can see this should work but I obviously have some syntax incorrect somewhere.
5 REPLIES 5
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2010
11:18 AM
08-03-2010
11:18 AM
I don't use VB at all, so these things may not be issues, but I notice two things that look wrong to me. First, you use set to increment the counter, but not for the initial assignment to 0. Second, you do not dim the obj variable.
As a matter of style though, "For" loops are usually preferred in cases where you need a counter. Opinions certainly differ, but something like this would generally be considered better:
As a matter of style though, "For" loops are usually preferred in cases where you need a counter. Opinions certainly differ, but something like this would generally be considered better:
For i = 1 to 10
aqUtils.Delay 100
set obj = browser.NativeWebObject.Find("class", "confirmboxcont")
If obj.Exists Then
Exit For
Next
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2010
09:48 PM
08-03-2010
09:48 PM
The problem is I don't want it to run 10 times. I want it to run ten times at the most before exiting so I don't get stuck in a loop if the do loop exit parameter doesn't become available.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2010
11:47 PM
08-03-2010
11:47 PM
Hi,
Actually, Tony's code does exactly what you need. It tries to obtain an object ten times and exits the loop right when the object is found even if ten iterations haven't passed.
Actually, Tony's code does exactly what you need. It tries to obtain an object ten times and exits the loop right when the object is found even if ten iterations haven't passed.
------
Yuri
TestComplete Customer Care Engineer
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Yuri
TestComplete Customer Care Engineer
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2010
11:52 PM
08-03-2010
11:52 PM
Ah, so it does. Guess I should have looked at the code harder.
I'm really not very good at this apparently. 🙂
I'm really not very good at this apparently. 🙂
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2010
02:08 AM
08-04-2010
02:08 AM
Hi Alex
Something else you might find useful for future reference is that when assigning a value to a variable, you do not need the Set statement. Use Set only when assigning an object to a variable.
So your line, Set i = i + 1, should simply read i = i + 1
Regards
Stephen.
Something else you might find useful for future reference is that when assigning a value to a variable, you do not need the Set statement. Use Set only when assigning an object to a variable.
So your line, Set i = i + 1, should simply read i = i + 1
Regards
Stephen.
