![]() |
|
|
Variables in ASP (VBScript)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 <% 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" %> 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.
9variable 'is not a valid variable
name as it begins with a number 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
Site developed by Michael Wall - Web Design Belfast N.Ireland. |
|