VBScript: Multidimensional Arrays, Statements, and Commenting - If...Then...Elseif
(Page 4 of 6 )
If you want to set multiple If then Elses, you would use the ElseIf statement. Behold!
<html>
<body>
<script type="text/vbscript">
Dim sitcom
sitcom = "Greatest American Hero"
if sitcom = "Alf" Then
msgbox "Don't eat my cat!"
elseif sitcom = "Three's Company"
msgbox "Larry said to meet him at the Blue Oyster"
elseif sitcom = "Alice"
msgbox "Kiss my grits!"
elseif sitcom = "Greatest American Hero"
msgbox "Prepare for a crash landing"
else
msgbox "Hey turn the tv, Alf is on!"
End If
</script>
</body>
</html>
Again, we create a variable named sitcom and assign it a value. Then we run through a series of statements, asking if the value of sitcom is equal to Alf; if it is, the program creates a pop-up box that says "Don't eat my cat!" Otherwise it moves on to the next statement and asks, is the value equal to Three's Company? If so, it creates a pop-up that says "Larry said to meet him at the Blue Oyster." It continues on in this manner until it finds a match. Finally at the end, if no match is found, it creates a pop-up box that says: "Hey turn the tv, Alf is on!"
However, since it does find a match, the program shows the following message in a pop-up box and exits out of the If statement:
Prepare for a crash landing
Next: The Select Case >>
More BrainDump Articles
More By James Payne