Conditional Branching

If condition then
ElseIf condition then
End if
For example:

Dim intInput
intInput = -1

while intInput < 0
intInput = InputBox(“Enter a positive number”)

If intiInput = 1 Then
msgbox (“Thank you”)
ElseIf intInput = 2 Then
msgbox (“Okay”)
msgbox (“Go to Hell”)
End If
Select Case testexpression
[Case expressionlist-n
[Case Else
[else statements]]
End Select

When we have to get a value from the user and we need to respond in several different ways. If else becomes tangled, long tedious and idiotic. So in comes the messiah select case. we can use Select case to test an expression seeing which of the several cases it matches.

For example
Dim intinput
intinput = -1

while intinput<0
intinput = InputBox(“Enter positive number”)

Const intmax = 100

Select case intinput

case 1: msgbox(“Yes”)
case 2: msgbox(“Yippe”)
case 3: msgbox(“Easy”)
case is > intmax: msgbox(“too big sorry”)
case else: msgbox(“Please try again”)

End Select

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s