This section provides tutorial examples on how to use variables and expressions in VBScript language.
Special rules about variables and expressions:
Variables used without declarations are called "variant" variables.
Variant variables can be used to store different data types.
Variable names are case insensitive.
"=" is the assignment operator. But it is also the Boolean equality operator.
"&" is the string concatenation operator.
Here is a sample ASP page, variable.asp:
<script language="vbscript" runat="server">
' variable.asp
' Copyright (c) 2002 by Dr. Herong Yang
' This program demonstrates some special rules about variables and
' expressions.
'
response.write("<html><body>")
response.write("<b>Tests on variables</b>:<br/>")
i = 1 + 2 + 3
s = "Sum = "
s = s & i & "<br/>"
i = i=6
response.write(s)
response.write("Is the answer correct? " & i)
response.write("</body></html>")
</script>
Output:
Tests on variables:
Sum = 6
Is the answer correct? True
"i = i=6" is a very unusual statement. First of all, variable "i" has changed its data type
from integer to Boolean. Secondly, two "=" signs are used next to each other, the first
one is an assignment operation, and the second one is a Boolean equality operator.