Sunday, June 5, 2016

Learn VB script Part 5

Using Conditional Statements


If...Then...Else Statement

If...Then...Else: Conditionally executes a group of statements, depending on the value of an expression.

Syntax:

If condition Then statements [Else elsestatements ] 

OR

If condition Then
   [statements]
[ElseIf condition-n Then
   [elseifstatements]] . . .
[Else
   [elsestatements]]
End If 


Example: 
'If...Then...Else

Total = Inputbox("Please enter the total marks in number ")

            If   Total >= 50 Then
            
                        MsgBox  "Pass"
            
            Else 
            
                        Msgbox "Fail"
            

            End If



Example: 
'If....ElseIf

Total = Inputbox("Please enter the total marks in number")

            If   Total < 50 Then
            
                        MsgBox  "Fail"
            
            ElseIf  Total >=50 and Total <=60   then
            
                        Msgbox "Second Class"

            ElseIf  Total >60 and Total <80   then
            
                        Msgbox "First Class"

            ElseIf  Total >=80  then
            
                        Msgbox "Distinction"

            Else

                        Msgbox "Invalid Marks"
            

            End If





No comments:

Post a Comment