tags:

views:

35

answers:

2

Working in ASP classic (not .NET) is frustrating. I really need a define statement akin to the define statements in C, C++. Is this possible?

+1  A: 

You can always just declare variables. If you're trying to use it for conditional compilation, you can sort of do it like this:

<% If SomeFlagDeclaredEarlier = True Then %>
    <!-- #include FILE="SomeConditionallyUsedFile.asp" -->
<% End If %>

And you can use that construct to also define expressions.

Joel Coehoorn
ALthough of course the conditional file is still included so you can't use this approach to include mutually exclusive files (for example files which declare the same variable names).
AnthonyWJones
+2  A: 

In an ASP web site its really useful to ensure that all ASP files declare a common include at the top:-

<!-- #include virtual="/globalInclude.asp" -->

This is a good place to put variables that you can then use to conditionaly skip stuff, for example you could include this code in the global include:-

class CGlobalDefinitions
    public Debug
end class

dim DEFINE : set DEFINE = new CGlobalDefinitions
DEFINE.Debug = true

Now everywhere in your ASP code you can use the code:-

if DEFINE.Debug then
    '' # Do stuff only when debugging is required
end if

Note using a class to hold your "DEFINE"s limits the impact creating various such flags on the each pages namespace, you wouldn't want your define to collide with another variable in an ASP page .

AnthonyWJones