Go to: Articles List

All About Variables Part 1 : Defining and Using
Part 1 | Part 2 | Part 3

The one important thing to know about variables in ASP (VBScript) is that there is only one type: variant. All variables are of type variant. Each variable can have a different subtype. There are 10 different subtypes of type variant (that you will probably use).

How to declare variables:

Dim MyVar1

You do not specify the subtype when you declare variables. You can however convert a specified variable to a particular subtype. This is described in Part 2.

Variable names guidelines:
- must start with alphabetical character
- can't contain any periods or type-declaration characters
- must be unique within the same scope (see below for a note about scope)
- must be 255 characters or less

Variable name suggestions:
- One philosophy on naming conventions is to start them all with the type you are going to use them as, like strLastName for strings, boolQuestionOne for Boolean, etc.
- Some places (like certain companies) have specific naming conventions like starting all variables with the team name that created them: TeamA_LastName. The reason for this is to help easily distinguish who and where the variable was declared and used.
- The best thing to do is find a style that you like and stick to it. Name your variables with names that you will be able to decipher. Soon you will develop your own style.

How to use variables:

To use a variable simply include it's name in your code:

var2 = FormatNumber(var1, 2)
var3 = "This String..."
var4 = var5 + var6

Some points to remember when using variables:
- Scope: A variable can only operate in the scope that it was defined. What this means is that if you define a variable in a function you define, only that function will be able to "see" or use that variable. To make a variable "visible" to all of your functions declare them at the beginning of you code and outside any functions or subroutines.
- When you are adding one variable to another (math wise) and you have not explicitly made them of a number subtype, you might get the two variables returned as a string concantenated. So instead of doing 2+2 and getting 4, you would get 22, which is the two variables concantenated.