Includes dilemma

Hello experts,

I have a file, MyClass.asp. This file defines the class MyClass, and some functions within that class.

MyClass.asp is included in the file IncludeA.asp, and also in the file IncludeB.asp. IncludeA.asp is itself included in various files on the site, as is IncludeB.asp.

The problem is, there is one file that includes BOTH IncludeA.asp AND IncludeB.asp, causing a "Name redefined" error since both of these includes are trying to define MyClass.

The only way around this I've been able to figure out is to remove the MyClass.asp include from IncludeB.asp, and but I'm not happy with that solution as it requires me to remember that any time I include IncludeB.asp but not IncludeA.asp, I need to include MyClass.asp as well. Is there a better solution? Perhaps a way to modify MyClass.asp so it checks to see if the class has already been defined before defining it again?

Thanks!
EffinGoodAsked:
Who is Participating?
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
i don't believe there is an easy way to do this, as once you define something in asp, you cannot redefine it, and there's no way to check if it's been defined. there is a way to check to see if it's been created in memory, but that's a different concept.

One idea I have is maybe in IncludeB.asp, you can do a check of the current page (using the Request.ServerVariables collection) and if it's the page you don't want to include MyClass.asp on, then don't do the include. something like this:

IncludeB.asp

<%if Request.ServerVariables("SCRIPT_NAME") <> "somepage.asp" then%>
       <!-- include virtual = "MyClass.asp" -->
<%end if%>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.