|
Conditional Statements
Part:
1
2
3
(Continued from previous part...)
"Select Case" Statement Example
To help you understand how "Select Case" statements work, I wrote the following the example, condition_case.html:
<html>
<body>
<!-- condition_case.html
Copyright (c) 2006 by Dr. Herong Yang. http://www.herongyang.com/
-->
<pre>
<script language="vbscript">
iDay = 4
Select Case iDay
Case 0
sDay = "Sunday"
sOpenHours = "closed"
Case 1, 2, 3, 4, 5
sDay = "a weekday"
sOpenHours = "open from 9:00am to 9:00pm"
Case 6
sDay = "Saturday"
sOpenHours = "open from 9:00am to 5:00pm"
Case Else
sDay = "unkown"
sOpenHours = "undefined"
End Select
document.writeln("")
document.writeln("Today is " & sDay)
document.writeln("The library is " & sOpenHours)
</script>
</pre>
</body>
</html>
Here is the output:
Today is a weekday
The library is open from 9:00am to 9:00pm
Hope you know how to use "Select Case" statements now.
Conclusions
Remember that:
- "If" must be followed by a condition and "Then".
- "ElseIf" is one word, no space.
- "Case" is followed by a list of expected values.
- Unlike C language, no need to break statements in "Case" clauses.
Part:
1
2
3
|