ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Getting Scripts to Run on a Schedule
The Top 10 ASP Links @
What is and Why Do I Need It?

Quick query design
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

Scope out your variables
In ASP, script- or page-level variables are available across all of the code on any page for the lifetime of that page. These variables are declared outside the scope of any particular procedure or function. Procedure-level variables, on the other hand, are declared within a function or procedure and are available only within the scope of that function. That means you can access the value in the variable only within the context of its function or procedure. The code below demonstrates how to declare both script- and procedure-level variables:

<%@ LANGUAGE="VBScript" %>
<META name="VI60_defaultClientScript" content="VBScript">
<META name="generator" content="Microsoft Visual Studio 6.0">
<SCRIPT id="clientEventHandlersVBS" language="vbscript">
Dim MyPageVariable ' Script level variable
Sub document_onclick
Responsedocument.Wwrite (MyLocalVariable) & "<BR>"
' Out of Scope
Responsedocument.Wwrite (MyPageVariable)

End Sub

Sub MyProcedure()
Dim MyLocalVariable ' Procedure-level variable
MyLocalVariable = "Available in the function"
MyPageVariable = "Available in the page"

End Sub

<P> </P>


In the example, MyLocalVariable is available only to the procedure MyProcedure. When the variable is called upon to display its contents from within the calling procedure, it has nothing to display since it is out of scope. The variable MyPageVariable, on the other hand, is available to reveal its contents.
Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers