A variable acts as a container holding or storing a value in the server computer's memory. We can then use or change the value of the variable throughout our code. Thus we could create a variable myFavouriteTeam that holds my favourite football team namely 'Spurs' and print out the value of the variable on our page. Note that to declare a variable in ASP/VBScript we use the Dim statement.
Example
<%
Option Explicit
'declare your variable
Dim myFavouriteTeam
'assign a value to our variable
myFavouriteTeam="Spurs"
'the above variable myFavouriteTeam holds
the value Spurs
response.write myFavouriteTeam
'the output will be Spurs
%>
In ASP/VBScript there is only one datatype, and that is variant. A variant can hold either strings or numbers, and will act as a number if its numeric, and as a string for string values.
In ASP/VBScript, it is not necessary to declare your variables before using them though it is good practice. You must use the Dim statement to declare variables as shown in the example below. You should also have a look at the Option Explicit tutorial which relates to variable declaration.
Here is an example where we assign a value to a couple of variables and then use them in the script.
<%@ Language="VBScript" %>
<% Option Explicit %>
<%
'Commented lines starting with an apostrophe
are not executed
'Declare your variables
Dim temperature, country
temperature=28
country="Ireland"
response.write "The temperature is " & temperature
& " in " & country
%>
The output is: The temperature is 28 in Ireland
The variable value will be kept in memory for the life span of
the current page and will be released from memory when the page
has finished executing.
In naming variables in VBScript you must be aware of these rules;
9variable 'is not a valid variable
name as it begins with a number
_variable 'is not a valid variable
name as it begins with an underscore
variable. 'is
not a valid variable as there is a period (full stop)
variable 'both
these variables in red are the same when using VBscript
VARIABLE
If the name of your variable breaks the rules then you'll encounter a fairly obvious error message like the one below.

Also note in the case above that Strings require quotes and numeric values don't. With the example above you can see that tempature=28 doesn't have quotes whereas country="Ireland" does.
Read our related tutorial on Variables and Constants
Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.
Get your best asp web hosting provider now and save 25%