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

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
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 @ Microsoft.com
What is Adovbs.inc and Why Do I Need It?

QUICK TIP:
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" %>
<HTML>
<HEAD>
<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
MyProcedure()
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
%>
-->
</SCRIPT>
</HEAD>
<BODY>


<P> </P>

</BODY>
</HTML>

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: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

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