VBScript: Multidimensional Arrays, Statements, and Commenting - The Select Case
(Page 5 of 6 )
As an alternative to the Elseif statement you could use the Select Case statement, which saves time and space in a program and is easier to read. Here is a sample program based off of our previous program:
<html>
<body>
<script type="text/vbscript">
Dim sitcom
sitcom = "Greatest American Hero"
Select Case sitcom
Case "Alf"
msgbox "Don't eat my cat!"
Case "Three's Company"
msgbox "Larry said to meet him at the Blue Oyster"
Case "Alice"
msgbox "Kiss my grits!"
Case "Greatest American Hero"
msgbox "Prepare for a crash landing"
Case Else
msgbox "Hey turn the tv, Alf is on!"
End Select
</script>
</body>
</html>
This code functions in the same manner as our previous example, only it is much more efficient. You will notice that at the end of the code I used a Case Else; this isn't required, but it gives you the option of saying if none of the criteria is met, do this.
Next: Commenting Your Code >>
More BrainDump Articles
More By James Payne