COMMAND | PURPOSE / EXAMPLE |
<script type="text/VBScript"> | HTML tag use to indicate the start of VBScript statements |
option explicit |
First statement in program. Forces all variables to be declared. |
rem comment |
Comment (or Remark) Statement: Used to document program rem Written by Sue Chen |
dim varname | Dimension Statement:
Used to declare a variable, where varname is the
variable's name. dim carType |
varname
=
convfunct(inputbox("prompt"))
|
Assign Input Data
Statement: Used to assign user entered data to
variable varname. A dialog box with the message
prompt will appear on the screen. The convfunct
determines the type of data: cstr is used for text data cint for non-decimal numeric data csng for numeric data that has decimals
carType = cstr(inputbox("Enter make of car."))
|
varname1 = varname2 + varname3 | Assign Statement:
Used to assign a computed value to variable
varname1. Valid arithmetic operators are
+ - / *
. totalMiles = endMiles - startMiles |
document.write("text"
& "<br>")
-or- |
Display a
Single Line Statement:
Used to print text and/or variable data on a single
line. document.write("Sue Chen - Basic Problem One" & "<br>") document.write("Make of car: " & carType & "<br>") |
document.write("<table>") document.write("<tr>") document.write("<td>" & "text") document.write("<td>" & varname ) etc. document.write("</table>") |
Display Table Row Statement:
Used to print text and/or variable data in columns.
Note: These must appear within <table>...</table> tags
document.write("<table>") |
if
condition then
truestatement end if |
If / Then Statement: Used to change statement execution order.
The truestatement will only be executed if the
condition is true.
if milesPerGallon < 10 then |
if
condition then
truestatement else falsestatement end if |
If / Then / Else Statement: The truestatement will
be executed if the condition is true, and the falsestatement will be executed if the condition tests
false. if totalMiles > 200
then |
for cntvar =
startvalue to endvalue loopstatements next |
For / Next Statement:
Used to
loop through the loopstatements as many times as it takes
cntvar to go from startvalue to endvalue adding
1 to cntvar each time.
for carCount = 1 to 5 |
do while condition loopstatements loop |
Do While Statement: Used to
loop through loopstatements as long as condition
remains true. (Caution: The loopstatements
must contain code that causes the condition to test false
or else the loop will run forever! )
carType = cstr(inputbox("Enter car type or click
Cancel button")) |
select case true
case expression1 statement(s)... case expression2 statement(s)... case else statement(s)... end select
|
Select Case Statement: Used to
choose different statements based on different values for a given
variable. If expression1 evaluates True then
expression1's statements are executed.
However, if expression1 evaluates False then the next expression is
tried. If no match is made, then the statements under the case else
are executed. select case true |
</script> | HTML tag use to indicate the end of VBScript statements |
HTML tags used construct a VBScript report page:
<html><head><title>
Visual Basic Problem One
</title></head><body>
<script type="text/VBScript">
-- ALL VBScript STATEMENTS GO HERE --
</script></body></html>