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?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
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:


<%if Request.ServerVariables("SCRIPT_NAME") <> "somepage.asp" then%>
       <!-- include virtual = "MyClass.asp" -->
<%end if%>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.