Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subroutines in an ASP web page 1

Status
Not open for further replies.

innmedia

Programmer
Mar 24, 2000
108
US
I have a long page of code I wish to shorten by implementing subroutines for the repetitive sections. I'm confused where to put the subroutines. It doesn't seem like I would put the subroutines within the same <% ... %> portion of the page. If that were the case how does the page know not to run the subs until the original code calls them. Do they go in the <Head>?


Thanks!
 
You can put them wherever you like. The general convention for functions (or subroutines, or whatever) is to put them at the end of the page, and then call them wherever you like.

It really doesn't matter, though, because when the compiler encounters code encapsulated in
sub -- end sub
it will not execute the code in there until there is a call made to it --

They have to go inside the <%%>'s though, because it's still ASP code.
penny.gif
penny.gif
 
In a sense, the first VBScript encountered is executed as if it started with a SUB MAIN with no parameters. When the next procedure is encountered, it is as if an END SUB were inserted for the MAIN SUB just before it. The DIMs in the &quot;MAIN&quot; procedure however are considered as Module level declarations, available to all procedures.
 
Thanks to all that answered. As long as the compiler understands then great!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top