WebBuilder101 - Making the web happen!
Need Web Dev software? Here is the place to
Flash Point

Working with Local and Global variables in ASP

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 Next

.

 

More Resources
An Introduction to ASP
Working with Form Input
How to create a .txt file
ASP 101
Haneng
ASPworld
ASPfaq

Suggested Reading

Beginning Active Server Pages 3.0
JavaScript Bible
Red Hat Linux
Dreamweaver 3.0
HTML Bible



Download WB101 Wallpaper
• Web Builder 101 Wallpaper Get it!.
• Find out how to create your own Wallpaper Teach me!.
Sign up for our Newsletters
• Web Building Sign me Up!.
• Net Alert! Sign me Up!.
Need Help?
• Contact Support Click here.
• E-mail the Webmaster Click Here.
• Search Tips Click Here.

Webbuilder101.com © 1998 - 2003 Copyright and Terms of Use
Send mail to: webmaster@webbuilder101.com

» About » Support

» FAQ » What's New » MyLog

Web Builder 101 Web Builder 101 - Making the Web Happen Web Builder 101 - Making the Web Happen
.