Conditional Branching

IF..THEN ELSE
———————
SYNTAX
If condition then
[statements]
ElseIf condition then
[statements]
Else
[statements]
End if
For example:

Dim intInput
intInput = -1

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

If intiInput = 1 Then
msgbox (“Thank you”)
ElseIf intInput = 2 Then
msgbox (“Okay”)
Else
msgbox (“Go to Hell”)
End If
———————
SELECT CASE
———————
SYNTAX
Select Case testexpression
[Case expressionlist-n
[statements-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”)
Wend

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s