Home / code / asp

Variables in ASP,

Variables have a name and can contain a value. They also have a datatype. So you sometimes you can't just compare one variable with another, you have to convert them.

The name of a variable
The name of a variable must start with a letter(a-z). The rest can contain a combination of letters and numbers.

The maximum length of a name can be 255 characters.

The names are names in VB-Script are case-insensitive, he doesn't make a difference between UPPERCASE and lowercase. (counter=Counter=COUNTER)

It is recommended you use clear names.

Definition of a variable
You define a variable with the instruction DIM

Example:
DIM counter, length, text

The definition is not obligated in ASP. Unless you have added the instruction "option explicit". Then you have to declare every variable.

Data types
There are no datatypes added with the definition of the variable.

Type Explanation
Numeric Whole, real, and floating-points numbers
Examples:
  • counter=5
  • real=-3.4
  • exponential=1.4E06
There are 5 different sub-types:
  • integer = whole numbers between -32 768 and 32 767
  • byte = whole numbers between 0 and 255
  • long = whole numbers between -2 147 483 648 and 2 147 483 647
  • single = floating-point numbers single precision
  • double = floating-point numbers double precision
String text always placed between double quotes ("")
You can also store numbers as string, but with calculation there is a different result
Example:
text="12"+"14" result is "1214"
sum=12+14 result is 26
Date Datum and time

Example:
Datum = #09/06/2000#
Time = #11.22#
Boolean These variables can only have 2 values. TRUE or FALSE

Example:
found= FALSE
Special
Empty
This is a variable when there is no value assigned to yet.
NULL
Mostly used with databases and objects. Refers to variables that are empty.
Object
The variable hold a pointing to an object.

With the function Typename(nameofthevariable) you can print the datatype of the variable.
datatype=TypeName(variable)

Constants

Constants are variables that are given a value with the definition, and cannot be changed in the programs.

CONST variable=value

There are several predefined constants.
Examples:
vbLongDate, vbSundays, vbCuan.

 

TOP

Latest script:

 

Books: