Select Case If Else Condition Do Loop
While Wend For Next Arrays Use of VB Script, VBScript
integration with QTP
In this section we will discuss about
conditional constructs, looping constructs and Arrays
So for Conditional constructs
like -: These are the execute statement or repetitive certain set of
code statements totally based upon condition.
So now given below is the conditional
construct which are available for VB Script
→ If – then - Else Condition
→ Select Case Condition
If – Then – Else Constructs
The If Then Else constructs are used to
decide or evaluate whether a condition is required to execute which
is false or true. All these are decided by the condition during the
execution time mean this is dynamic condition which work like that.
So The – If Then else statement can be nested on level to level
down
For Example:
Sub
Report Value(value)If value = 0 Then
MsgBox value
Else If value = 1 Then MsgBox value
Else If value = 2 Then Msgbox value
Else Msgbox "Value out of range!"
End If
As per above example we can add
multiple Else If clauses according to requirement, We also can use
Select Case constructs to avoid such type of repetitive. This will be
an alternative.
Select Case Condition
Definitely Select case is the best
alternative of If then else. Actually Select case condition code
create more efficient and readable code for user.
Actually Select Case structures work
with a one test expression or condition that will be evaluate only
once. Which will be at the top of the all complete structure. So
result of execution then will be compared with the value of each Case
in the available structure. If found any match then associated
statements with that specific Case will be executed.
Following is the good Example of
Select Case:
Select Case Document.Form1.CardType.Options(Selected Index).Text
Case “Master Card”
DisplayMC Logo
ValidateMCAccount
Case “Visa Card”
DisplayVisaCardLogo
ValidateVisaAccount
Case “American Express Card”
DisplayAMEXCardOLogo
ValidateAMEXCardOAccount
Case Else DisplayUnknownImage PromptAgain
End Select
Looping constructs:
AS it name suggest, Execution the group
of statement repeatedly. This type of loop will be totally based on
condition. Here loop will executed as long as condition will become
true. Following are the main Iterative constructs available :
→ Do Loop
→ While Wend
→ For Next
Do Loop Condition:-
This type of statement is used to run
the black of statements based on a conditions. These loop will
continue until the condition will not become or satisfied to True.
The Keyword While is used to confirm the conditions in this Do Loop
condition.
This condition can be tested before
entry into the loop or after the execution at least once.
While Wend Condition:
This condition is used by them who are
the familiar with the VB Script or its usage. Because this condition
have less flexibility that’s why it has not much use.
For … Next Condition:
The For Next loop can use to run a code block of statement for
specific numbers of times. For this loop need to use a counter
variable whose values can be increased or decreased with each
repetition of the loop. The Step Keywords is used to increase
or decrease the value of counter variable that is specified along
with it. The For Next statement can terminate before the counter
reaches its end value by using the Exit For statement.
For example:
Dim je, total
For je = 1 To 10 Step 2
Atotal = Atotal + j
Next
MsgBox “Your total is ” & total
MsgBox “Your total is ” & total
Arrays → Array is like a connected area in the available
memory refer by the general name.
Actually it is the variables having
same type of datatype. Arrays are used to saved the related data
value Therefore arrays are called Same data type values.
Declaring the Arrays →
We generally used two types of Arrays →
- Local Array: Local array can be declared only based on function or procedure where it need to execute. It works within the function or procedure.
- Global Arrays → Global array can be declared as globally which can be used whatever user desire either any place.A global array is an array that can be used by all functions and procedures. It is declared at the beginning of the VBScript Code
Example of Array:
Dim No_Passenger(4)
The No_Passengers can Save 5 values.
Assigning values to the array
No_Passengers(0) = 1
No_Passengers(1) = 2
No_Passengers(1) = 2
No_Passengers(2) = 3
No_Passengers(3) = 4
No_Passengers(4) = 5
Static And Dynamic :
VBScript gives flexibility to declare arrays either static or
dynamic.
A static arrays have some limited number of element. The
size of a static array can not be changed at run time.
A dynamic array can be re sized at any time. Dynamic arrays
are very useful when size of the array can not be decided. Then the
array size can be changed during run time.
In the Next Posts we will discuss about user defined functions,
procedures and sub Routines.
|
||
|
Advantages and Disadvantages of Automation Testing | |
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
Use of add-ins |
Cookies in QTP |
|
|
|
What is Object Spy in QTP | Ordinal Identifiers Alone can Make an Object Unique |
|
||
|
|
|
Test Automation Frameworks Types |
No comments:
Post a Comment