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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public scope?

Status
Not open for further replies.

influent

Programmer
Jan 11, 2001
131
0
0
US
This is sort of a newbie question I suppose. Would a simple ASP page ever need a scope of Public on any of its subs? What about ASP.NET?

If I have a page called Page1.asp, and one called Page2.asp, and Page1.asp has a Public function, can Page2.asp call that function as long as they're part of the application?
 
Place all the subs, routines and functions that you will use within multiple pages in a INCLUDE file. Then call the routine when needed.

Your pages will need a line like this just after your Body tag.

<!--#include virtual=&quot;/FileName.inc&quot; -->

Natuarlly, your file that contains your routines will have the .inc extension.

Mike Diaz...



 
Interesting question. I'll have to givethis one some thought.
Technically if you use an include like above, then the files are merged at runtime so the outside script has access to the private subs of the included script, and vice-versa.

The other way to do this would be to use the Server.Execute to execute a file... but this would execute the file independantly, ie the original file wouldn't have any access to the executed file anyways.

I guess the public would only make sense if you were creating classes and objects:
Code:
Class MyObject
   Dim a  'a is accesible only to me
   Public b   'b is accessible to the world
End Class

I used variables as ana example but is the same with functions, subs, etc.

So basically unless you are creating custom classes/objects than the Public scope is unnecessary.

-Tarwn

As a sidenote: mdiaz, why do you say an include file will naturally have a .inc extension?
________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Thanks Tarwn, that's exactly what I wanted to hear. Do all functions and classes within the global.asa file need to be Public?
 
Tarwn,

Don't know exactly, maybe it was the way I was brought up...

Just kidding. Thats the way I have always used it. No other reason. I'll research and maybe learn something new.
 
:) Wasn't criticizing. I generally use .asp extensions on my include files just to be sure no one can get the code from them.

As for the global.asa file. I did a little research but wasn't able to find anything that seemed to relate to this subject, has anyone else seen anything on this?

-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Tarwn,

I know you were not criticizing. I do remember reading something about others being able to view the contents of an include file.

Do you mean that someone can view a .inc file?

If I want to use an asp page for the same purpose do I then just name my include file Something.inc? With a tag like:

<!-- Include virtual=&quot;/SomeFile.asp&quot;> on my asp pages?

Mike Diaz...
 
No, you can actually save it with the .asp extension then reference it with that extension as well. An example of that is my sites will generally have something called GenScripts.asp that have my header, footer, and other &quot;generic&quot; scripts in functions. Then I just include it it and call those functions, exactly like the you would do with a .inc file. I'm assuming you could probably get away with saving it as justa bout anything, I don't know if the server filters out certain extensions or treats every file as text until it finds out otherwise.
Technically I guess you could include image files and such as well...though that would probably give the server fits as it tried to figure out what to do with them :p

-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top