Sunday, December 19, 2010

If Then Statement


The if-then statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates to true.

Syntax:


If <> Then

Block of the statement

End If



The above Syntax. If the Condition is TRUE the block of the statement will be executed. If if is FALSE nothing will be executed

The following example we have declared Integer type variable a,b and assigning the value for the variable a=10, b=10. Now the condition is true MsgBox(“A is Equal to B”) will be executed and display A is Equal to B.

Example1

Dim a, b As Integer
a=10
b=10
If a = b Then
MsgBox("A is Equal to B" )
End If


The following example we have declared Integer type variable a,b and assigning the value for the variable a=10, b=5. Now the condition is False.nothing will be executed.

Example2

Dim a, b As Integer
a=10
b=5
If a = b Then
MsgBox("A is Equal to B" )
End If