|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
ASP Quirk with Const
Seems like I stumbled on an ASP quirk, or I am missing something. Given the following ASP code:
<html> <body> <% If FOOBAR Then Response.Write "FOOBAR exists" Response.End End If Const FOOBAR = 1 %> ZZZ </body> </html> I would expect ZZZ to be displayed since FOOBAR is _not_ defined to begin with. Instead the web browser displays "FOOBAR exists". Why?? ?? Note that if I change: from: Const FOOBAR = 1 to: Const FOOBAR999 = 1 and leave the rest of the code the same, then the browser displays "ZZZ". Is the 'Const' statement somehow read BEFORE the 'If' statement???? Please explain this quirk. |
|
#2
|
|||
|
|||
|
I don't beleive that it is a quirk. When you define a variable with dim or constant, these are done as preprocessing directives. The compiler or whatever in ASP will check the code for errors like not dim variables if option explict is defined and shoot those errors beck before anything else.
|
|
#3
|
|||
|
|||
|
How then do I achieve the equivalent in C where I include the code only if it has not been included before:
#ifndef FOOBAR #define FOOBAR .... functions, code, etc. here.... #endif I can't do: <% If Not FOOBAR Then Const FOOBAR = 1 Sub X() ... End Function Y() ... End End If since I can't define Subs and Functions inside the If/End block. So I thought I'd do: If FOOBAR Then Response.End End If Const FOOBAR = 1 Sub X() ... End Function Y() ... End But it seems that in this case, FOOBAR will always be defined because of the presence of the Const FOOBAR = 1 further down in the code and, as the previous guy said, it is treated as a preprocessor directive. So how do I come up with a way to simulate the #ifndef/#define/#endif in C/C++ to only include and process the code if it has not already been included and processed before? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > ASP Quirk with Const |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|