VBScript 05
VBScript 05
Session 5
Dani Vainstein 1
What we learn last session?
Branching
Branching using If…Then…Else
statement.
Branching using Select Case
Dani Vainstein 2
Subjects for session 5
Dani Vainstein 4
Do While/Until
Dani Vainstein 5
Looping Through Code
Using Do…Loop Statement
Do[{While
Do [{While||Until}
Until}condition]
condition]
[statements]
[statements]
[ExitDo]
[Exit Do]
[statements]
[statements]
Loop
Loop
Do [statements]
Do [statements]
[ExitDo]
[Exit Do]
[statements]
[statements]
Loop[{While
Loop [{While||Until}
Until}condition]
condition]
Dani Vainstein 6
Looping Through Code
Using Do…Loop Statement
Dani Vainstein 7
Looping Through Code
Using Do…Loop Statement
Dani Vainstein 8
Looping Through Code
Using While…Wend Statement
Dani Vainstein 9
Looping Through Code
Using For…Next Statement
Dim x
For x = 1 To 50
MyProc
Next
Dani Vainstein 10
Looping Through Code
Using For…Next Statement
Dim j, itotal
For j = 2 To 10 Step 2
itotal = itotal + j
Next
Msg = "The total is " & itotal
Dani Vainstein 11
Looping Through Code
Using For…Next Statement
You can exit any For...Next statement before the
counter reaches its end value by using the Exit For
statement.
Because you usually want to exit only in certain
situations, such as when an error occurs, you should use
the Exit For statement in the True statement block of an
If...Then...Else statement.
If the condition is False, the loop runs as usual.
Dani Vainstein 12
Looping Through Code
Using For Each...Next Statement
Dani Vainstein 13
Looping Through Code
Exit Statement
Dani Vainstein 14
Excercises
Dani Vainstein 15
Lab 5.1
Input parameters names are From and To
Assume that both inputs are integers.
Display in reporter all the pairs between For and To
Use the For...Next loop.
Tip
Use the Step statement.
Concatenate to a temporary string.
Try your program for the following values
From = 2 : To = 10 (2,4,6,8,10)
From = 1 : To = 9 (2,4,6,8)
From = -7 : To = 3 (-6,-4,-2,0,2)
From = 50 : To = 41 (50,48,46,44,42)
From = -3 : To = -9 (-4,-6,-8)
Dani Vainstein 16
Lab 5.2
Input parameters names are Pswd.
Declare a constant MY_PASSWORD.
Declare a constant MAX_RETRY = 3.
If the password is correct display a micPass message.
If the password is typed wrong more then MAX_RETRY
times, display a micFail message.
Use the Do..Loop (While or Until).
Tip
Use the Exit Loop statement.
Dani Vainstein 17
Make sure to visit us
Tutorials
Articles
Projects
And much more
www.AdvancedQTP.com
18