KR Testing Solutions

Quality is effected by your work process

3: Conditional Statements

Conditional Logic

VBScript provides two statements that allow you to add logic that can alter the logical execution of scripts. This way your scripts can make decisions based on user or environmental criteria. These statements are listed below.
 ·       If…Then…Else. Guides the logical execution of a script based on one or more tested conditions.
·         Select…Case. Guides the logical execution of a script based on multiple tests performed against the same condition.

If…Then…Else

If condition Then statement [Else statement]

If you need to execute more than one VBScript statement as a result of your comparisons, then you’ll need to use the following syntax for the If…Then…Else statement.

If condition Then  

  statements  

ElseIf condition-n Then  

statements  

.  

.  

Else  

    

statements  

End If

For example, you could modify the IF…Then…Else statement in the previous example as shown here.

If  rupeesSent = rupeesReceived Then  

MsgBox "No rupess remaining now"  

rupeesOnhand = 0  

Else  

MsgBox "This rupess is balance"  

unitsOnhand = rupeesSent - rupeesReceived  

End If

Select Case

The Select…Case statement provides functionality that is very similar to the If…Then…Else statement. However, although the If…Then…Else statement can test a large number of different conditions, the Select… Case statement is better equipped to test a large number of criteria against a single condition. The syntax of the Select…Case statement is

Select Case value  

Case expression  

  statements  

  .  

  .  

Case expression  

  statements  

Case Else  

  statements  

End Select

Select…Case evaluates a single value as specified in the Select…Case statement and compares it against the values stored in each of the
Case
statements that follows as demonstrated in the following example.

Select Case myNumber

Case “1″
  MsgBox “The matching color is 1″
Case “2″
  MsgBox “The matching color is 2″
Case “3″
  MsgBox “The matching color is 3″
Case Else
  MsgBox “No Number matches”
End Select

Next Step – Looping Statements

February 5, 2008 - Posted by kuldeep kumar | Learn VBScript for QTP (Descriptive Programming) | | 1 Comment

1 Comment »

  1. [...] « Previous | Next » [...]

    Pingback by 2: Operators « KR Testing Solutions | February 5, 2008 | Reply


Leave a comment