Thursday, September 2, 2010

Conditional Statements

Select Statement
If Statement

Select Statement
syntax:
Select case testexpression
[case expression-list-n
[statements-n]]...
[case else
[elsestatements-n]]
End Select

'Script for select case statement
day1 = weekday(date)
select case day1
case 1
msgbox("Sleepy Sunday!")
case 2
msgbox("Monday again!")
case 3
msgbox("Just Tuesday!")
case 4
msgbox("Wednesday!")
case 5
msgbox("Thursday...")
case 6
msgbox("Finally Friday!")
case else
msgbox("Super Saturday!!!!!")
end select

If...Else...Statement
Syntax:
If statement takes the following format
{simple format} If condition Then statement(s) [else elsestatement(s)]
{block format}
If condition Then
[elseif condition then
[elseif statement(s)]]...
[else
[elsestatement(s)]]
End If

Script using if...else statement
timenow = hour(time)
if timenow = 10 then
msgbox("Just started...!")
elseif timenow = 11 then
msgbox("Hungry")
elseif(timenow = 12)then
msgbox("Ah, lunch-time")
elseif timenow = 16 then
msgbox("Time to go home!")
else
msgbox("Unknown")
end if

No comments:

Post a Comment