ASP is not a programming language. To program in ASP you actually need to know the VBScript, the
scripting language. All VBScript variable rules can be applied to your
ASP code. This lesson will teach you the basics of ASP Variables and some good
programming conventions.
A variable is always used to store information.
In the ASP file, if the variable is declared outside a procedure it can be changed by any script. If you are declaring a variable inside a procedure, it can be reated and destroyed every time the procedure is executed.
Declaring a Variable in ASP
Always declare all your variables before you use them,
even though it is not required. Nearly all programming languages require you to declare
variables so that it will increase your program's readability.
In ASP you declare a variable with the use of the Dim keyword, which means Dimension.
Dimension refers to the amount of space something takes up in the real world,
but in computer terms it refers to space in computer memory.
Variables can be declared all at once or one at a time . Below is an example of both methods
ASP Code:
<%
'Single Variable Declarations
Dim myVar1
Dim myVar2
'Multiple Variable Declarations
Dim myVar6, myVar7, myVar8
%>
ASP Variable Naming Conventions
Default language for ASP is VBScript and so it also uses VBScripts variable naming
conventions. These rules are:
1. Variable name must start with an alphabetic character (A through Z or a through z)
2. Variables cannot contain a period
3. Variables cannot be longer than 255 characters
4. Variables must be unique in the scope in which it is declared.
ASP - Assigning Values to ASP Variables
You can assign values in ASP using equals "=" operator.
Below we have set a variable equal to a number and a separate variable equal to a string.