|
By Eddy R.
4-3-00
Whether you just started to learn ASP or you are an ASP expert,
you've definitely dealt with both Local and Global variables at
one point or another. For the benefit of those who are learning
ASP, we'll go ahead and explain what Local and Global variables
are; for those who are ASP experts, this will be a refresher. Let's
get started.
Keep the following in mind: If you assign a value to a variable
and then assign another value to the same variable, then the old
value will be replaced with the new one - that is not the case with
Local variables.
Local Variables
Local variables are variables that exist only during the lifetime
of the procedure that created them. In other words, once a procedure
has stopped running (has finished what it was supposed to do), the
variable that was created at the beginning of the procedure ceases
to exist therefore you can assign different values to the same variable.
Let's see an example of how they work (variables are in green)
- this script will go in the BODY of your HTML document.
<% Sub Procedure_1 ( )
strText = "'This is a text string"%>
<%=strText%>
<%End Sub%>
<% Sub Procedure_2 ( )
strText = "This is another text
string"%>
<%=strText%>
<%End Sub%>
<p>This is the result for the first procedure: <%Procedure_1(
)%></p>
<p>This is the result for the second procedure: <%Procedure_2
( )%></p>
<p>This is the result for the first procedure: <%Procedure_1(
)%>, again."%>
See
it in action
As you can see, strText ceased to exist once the first procedure
finished executing thus you could assign a new value to the same
variable in the second procedure. The "old" value of the
variable could be called again if the first procedure is once again
invoked - as it is shown in the example.
Tell
me about Global Variables 
|