Constants in C# and VFP
#DEFINE, #INCLUDE, #UNDEF
C# Syntax Notes
Constants in C# have their value fixed at compile time:
const double VAT_Rate = 0.175;
Fields can also be defined as being
to give a little more flexibility:
double readonly VAT_Rate;
The value of a readonly field can be set in the constructor of its class
but is then fixed for the lifetime of the class. In this example, the VAT rate
might be being read from some external data source as the class is being
VFP Syntax Notes
Constants in Visual FoxPro exist from the moment that they are defined. After this
#DEFINE CTRL_C 3
the compiler will replace all occurrences of the characters 'CTRL_C' with the
Do not try to put an '=' sign into this declaration. It's a great
temptation, but it's wrong.
Be aware that there is no sanity check on this process, it's just a mindless
search and replace through the source code. You can choose to redefine a FoxPro
#DEFINE BROWSE "DELETE"
This way lies madness.
FoxPro has an
directive which stops the replacement process. This can be placed anywhere in any
of the files of a project and means that constants can be made local to any region
of code - down to perhaps a few lines in one procedure. This was useful in the days
of long monolithic programs but is rarely used now.
FoxPro also has the #INCLUDE directive which pulls a header file of
constants into the program. The FoxPro.H file supplied with the
language includes the definitions of many useful constants such as
COLOR_BLUE. It's useful to create a standard include file for your
own project and to include FoxPro.H into this file.
Foxpro include files
#DEFINE NOENTRIES "-None-"
#DEFINE ALLENTRIES "-All- "
#DEFINE APP_FALSE "False"
#DEFINE APP_TRUE "True"