![]() |
|
|
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. 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. 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"
Site developed by Michael Wall - Web Design Belfast N.Ireland. |
|