Tuesday, April 13, 2010

VB Scripting - If Statement

Previous11121314151617181920Next


If Else statement in VB script is used when you want to execute a block of code based on certain condition.


Syntax for If Else Statement


If [Condition] Then
AAAACode
AAAACode
Else
AAAACode
AAAACode
End If


Example to show how If Else Statement is Used


We will write a script asking the user to enter the average scored and based conditions given appropriate message is displayed.

'Code to demonstrate If Else condition
Varint1 = Inputbox("Enter the average score you gained:")
If Varint1 > 80 Then
AAAAmsgbox "You scored " &Varint1& " percentage and are the winner"
Else
AAAAmsgbox "You scored " &Varint1& " percentage and do not qualify."
End If


If the user enters 85 then the output displayed will be

You Scored 85 percentage and are the winner


If user enters any thing less than 80 say 75 the output displayed will be

You Scored 85 percentage and do not qualify.


Previous11121314151617181920Next

1 comment:

Naveen Kumar S said...

You Scored 85 percentage and do not qualify.
it should be 75 in the result box

Post a Comment