Codefixer - ASP tutorials, resources and software
asp.netPRO “Best ASP.NET Host” – DiscountASP.NET
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Wednesday 14 May
MembersPro PayPal - ASP Membership software

asp.netPRO “Best ASP.NET Host” – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Constants in ASP (VBScript)

In our 'Variable' tutorial we showed how a variable acts as a container holding or storing a value in the server computer's memory. Well so does a constant.
With a variable we can change the value of the variable throughout our code, with a constant we can't. Have a look at the code for example 1.

Example 1:

<%
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
'assign a new value to our variable

myFavouriteTeam="Spurs Reserves"
'the above variable myFavouriteTeam now holds the value Spurs Reserves
response.write myFavouriteTeam
'Our browser will now display Spurs Reserves
%>

Note that the value of the variable myFavouriteTeam changes throughout the script from Spurs to Spurs Reserves.
The value stored in a constant cannot change throughout the life of a script or application after it has been declared.

To declare a const in VBScript we use the Const keyword. The constant is declared and assigned the value all on the same line.

Const MyConst=2

In we attempt to re-assign the value of the constant as we did with the value of the variable we'll get a run time error.

Also note in the case above that strings require quotes and numeric values don't as shown below.

Const MyConst=2
Const MyConst="myString"
LinksPro - Directory  and Link  Management Software




ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software