You are on page 1of 2

ASP delimiters

ASP code is opened and closed with the use of delimiters. When you are going to write ASP code use
the opening tag <% and when you have finished writing your code use the closing tag %>
Variable
Declaring variables in ASP is simple, especially since all variables are of Variant type. To declare a
variable in ASP/VBScript we use the Dim statement which means Dimension. in computer terms it
refers to space in computer memory. If you wanted to print out the variables, you could use the ASP
'Response.Write' command. Variables can be declared one at a time or all at once. Below is an
example of both methods.
<%
'Single Variable Declarations
Dim myVar1
Dim myVar2
'Multiple Variable Declarations
Dim myVar6, myVar7, myVar8
%>
In naming variables in VBScript you must be aware of these rules:
Variables must begin with a letter not a number or an underscore
They cannot have more than 255 characters
They cannot contain a period (.) , a space or a dash
They cannot be a predefined identifier (such as dim, variable, if, etc.)
Case sensitivity is not important in VBScript
Data types
Data types are essential part of any programming language primarily because they allow
error checking and determine the size of memory allocation, what kind of information can
be stored, and what operations can be performed to a variable
To make programming languages more efficient, data is categorized into most common types:
integer, float, double, string, Boolean, date, and currency
Integers
An integer is a whole number, without a fractional portion. Examples include number of automobiles
a student owns, number of hours in a day, number of days in a year, etc
Floats
A float is a number with fractional portion such as -1.3, -.45, 4.56, 10.0000, etc. Examples include 1
divided by 3, amount due at a check-out, etc
Double
A double is similar to floats except the precision is twice as much as of a floating-point number. An
interesting example is temperature, which has many trailing digits but is rounded-off to an integer for
simplicity. Thus doubles have more precision and require more memory.
String
A string type consists of letters, numbers, or symbols. "Active Server Pages", "5mph", and "15" are all
example of strings. It is very important to note that the strings are included inside of double quotation
marks.
Boolean
Boolean types are used to indicate any one of two states, for example, TRUE or FALSE, 0 or 1, ON
or OFF, etc. A Boolean type is used to make decisions depending on the value of the variable used to
represent Boolean type.
Date
A date type can hold time or date. It is a great feature of VBScript. The date type can be used to
represent strings and/or integers.
ASP: Constants
Constants just as variables are used to store information. The main difference between
constants and variables is that constant value can not be changed in the process of
running program. If we attempt to re-assign the value of the constant we'll get a run
time error.
It can be mathematic constants, passwords, paths to files, etc. By using a constant you
"lock in" the value which prevents you from accidentally changing it. If you want to run a
program several times using a different value each time, you do not need to search
throughout the entire program and change the value at each instance. You only need to
change it at the beginning of the program where you set the initial value for the
constant.
To declare a constant in VBScript we use the Const keyword. Have a look at the
following example:
Const PI = 3.14159, Wg = 2.78
Next example demonstrates the advantage of constants: during the calculations with
number PI, you can type in your code only constants names instead of typing this
number each time
vCircle = PI * vRadius^2

You might also like