VBScript – Decision Making


binУЄre option betrug                 VBScript – Decision Making

Decision making allows programmers to control the execution flow of a script or one of its sections. The execution is governed by one or more conditional statements.

In this chapter we will discuss general form of a typical decision making structure found in most of the programming languages:

General Decision MakingFig: Decision making image 1

IF..ElseFig: Decision making image 2

VBScript provides following types of decision making statements:

go Statement beställa Sildenafil Citrate Description
IF An  http://www.segway.fi/?kastoto=professionelle-trading-signale-bin%C3%A4re-optionen&0d6=c7 if statement consists of a Boolean expression followed by one or more statements.
IF

.

.

ELSE

An  source url if else statement consists of a Boolean expression followed by one or more statements. If the condition is True, the statements under  http://makse.com/?kremel=any-good-anime-dating-sims&2fa=7b If statements are executed. If the condition is false, Else part of the script is Executed
IF…ELSEIF An  30 year old woman dating 19 year old man if statement followed by one or more  source ElseIf Statements, that consists of Boolean expressions and then followed by an optional  dating in barcelona online else statement, which executes when all the condition becomes false.
NESTED IF An  flirten fУМr frauen kostenlos if or  watch elseif statement inside another  http://huntersneeds.net/rigaro/2625 if or  elseif statement(s).
SWITCH buy generic cialis canada switch statement allows a variable to be tested for equality against a list of values.

 

azulfidine 500 mg en espanol VBScript If Statements

An IF statement consists of a Boolean expression followed by one or more statements. If the condition is said to be True, the statements under IF condition(s) are Executed. If the Condition is said to be False, the statements after the If loop are executed.

tamoxifen dosierung 10 mg Syntax :

The syntax of an If statement in VBScript is:

If(boolean_expression) Then

Statement 1

…..

…..

Statement n

End If

Flow Diagram

IF

IF Statement Example:

Dim a,b

A = 20

B = 10

 

If a > b Then

   Print “a is Greater than b”

End If

Output will be:

a is Greater than b

VBScript If Else Statements

An IF statement consists of a Boolean expression followed by one or more statements. If the condition is said to be True, the statements under IF condition(s) are Executed. If the Condition is said to be False, the statements under Else Part would be executed.

Syntax

The syntax of an IF statement in VBScript is:

If(boolean_expression) Then

Statement 1

…..

…..

Statement n

Else

Statement 1

…..

….

Statement n

End If

Flow Diagram

 IF Else

Example of IF Else:

Dim a,b

A = 5

B = 20

 

If a > b Then

   Print “a is Greater”

Else

   Print “b is Greater”

End If

Output will be:

b is Greater

VBScript If..ElseIf..Else Statements

An If statement followed by one or more ElseIf Statements that consists of boolean expressions and then followed by a default else statement, which executes when all the condition becomes false.

Syntax

The syntax of an If-ElseIf-Else statement in VBScript is:

If(boolean_expression) Then

Statement 1

…..

…..

Statement n

ElseIf (boolean_expression) Then

Statement 1

…..

….

Statement n

ElseIf (boolean_expression) Then

Statement 1

…..

….

Statement n

Else

Statement 1

…..

….

Statement n

End If

Flow Diagram

if elseif else

If..ElseIf…Else Exaple:

Dim a

a = -5

 

If a > 0 Then

   Print “a is a POSITIVE Number”

ElseIf a < 0 Then

   Print “a is a NEGATIVE Number”

Else

   Print “a is EQUAL than ZERO”

End If

Results Will be:

a is a NEGATIVE Number

VBScript Nested If Statement

An If or ElseIf statement inside another If or ElseIf statement(s). The Inner If statements are executed based on the Outermost If statements. This enables VBScript to handle complex conditions with ease.

Syntax

The syntax of a Nested if statement in VBScript is:

If(boolean_expression) Then

Statement 1

…..

…..

Statement n

If(boolean_expression) Then

Statement 1

…..

…..

Statement n

ElseIf (boolean_expression) Then

Statement 1

…..

….

Statement n

Else

Statement 1

…..

….

Statement n

End If

Else

Statement 1

…..

….

Statement n

End If

Flow Diagram:

Nested IF

NB: If you look at the flowchart of Nested If and If ElseIf Else, it goes for the next If, if the condition is true in Nested If, where as it goes for the next If, if the condition is false in If ElseIf else.

Example of Nested If Statement:

Dim a

a = 23

 

If a > 0 Then

   Print “The Number is a POSITIVE Number”

   If a = 1 Then

     Print “The Number is Neither Prime NOR Composite”  

   Elseif a = 2 Then

     Print “The Number is the Only Even Prime Number”  

   Elseif a = 3 Then

     Print “The Number is the Least Odd Prime Number”  

   Else

     Print “The Number is NOT 0,1,2 or 3”  

   End If

ElseIf a < 0 Then

   Print “The Number is a NEGATIVE Number”

Else

   Print “The Number is ZERO”

End If

Output of the above piece of code will be:

The Number is a POSITIVE Number

The Number is NOT 0, 1, 2 or 3

Switch Statements in VBScript

When a User want to execute a group of statements depending upon a value of an Expression, then Switch Case is used. Each value is called a Case, and the variable being switched ON based on each case. Case Else statement is executed if test expression doesn’t match any of the Case specified by the user.

 

Case Else is an optional statement within Select Case, however, it is a good programming practice to always have a Case Else statement.

Syntax :

The syntax of a Switch Statement in VBScript is:

Select Case expression

Case expressionlist1

statement1

statement2

….

….

statement1n

Case expressionlist2

statement1

statement2

….

….

Case expressionlistn

statement1

statement2

….

….

Case Else

elsestatement1

elsestatement2

….

….

End Select

Flow Diagram:

Switch Statement

Example of Switch Statement:

Dim MyVar

MyVar = 1

 

Select case MyVar

   case 1

                Print “The Number is the Least Composite Number”

   case 2

                Print “The Number is the only Even Prime Number”

   case 3

                Print “The Number is the Least Odd Prime Number”

   case else

                Print “Unknown Number”

End select

Output will be:

The Number is the Least Composite Number

Go Back to UFT Tutorials Home Page