Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Accessing Constants
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00252941
Message ID:
00253052
Views:
18
>I've defined some constants in my main program, put when I call another procedure and reference the constant I get the error "variable not found". My understanding is you define the constant once and it should be available thoroughout the program.
>
>I've checked syntax and even moved the code to the main procedure where it works fine, but still it does not work in the called procedure.
>
>What's up with that?

You misunderstood. A #DEFINE is in effect not for the entire application, but for the file that it is physically located in; IOW, if you have a procedure file, any #DEFINEs in the procedure file will be in effect for all procedures and functions in that procedure file. if a physically different file references that constant, you need to include that #DEFINE in that file.

It's worse for Visual classes; each method needs to have the #DEFINES it uses declared in it.

An easy method to address this is to create a .H file containing your #DEFINES and #INCLUDE that file whereever it's needed. In VFP6, a new system variable, _INCLUDE, was added to VFP; if you put the name of a file in this variable, it will be automatically included and available to everything.

Realize that #DEFINEs are a compile-time directive; you won't be able to reference the constants you defined at compile time directly during runtime. This often causes confusion in the debugger, where you might want to watch for a variable to take on the value of something that you've #DEFINEd as a constant - the constant may not be available to the debugger, which can confuse you easily.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform