Library code snippets

Use Local Variables

Within subroutines and functions, you should use local variables rather 
than global variables whenever possible. Local, in this case, means that 
the variables are defined between the sub/function and end sub/function 
statements. Within subroutines and functions, access to local variables 
is faster than to global variables. Plus, it makes for cleaner and more 
readable code and easier debugging.

For example, instead of writing

<%
dim intCounter

function howMany
for intCounter = 1 to 100
next
howMany = intCounter
end function

response.write howMany
%>


you should write this instead:

<%
function howMany
dim intCounter
for intCounter = 1 to 100
next
howMany = intCounter
end function

response.write howMany
%>

Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of Use Local Variables.

Leave a comment

Sign in or Join us (it's free).

ElementK Journals

Want to stay in touch with what's going on? Follow us on twitter!