Database development and training for Birmingham and the midlands
Specialists in Microsoft Access and Visual Foxpro database training and development
I am happy to hear from existing clients but I am taking no new calls.
Constants in C# and VFP
VFP#DEFINE, #INCLUDE, #UNDEF
C# Syntax Notes
Constants in C# have their value fixed at compile time:
Fields can also be defined as being readonly to give a little more flexibility:
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 created.
VFP Syntax Notes
Constants in Visual FoxPro exist from the moment that they are defined. After this declaration:
the compiler will replace all occurrences of the characters 'CTRL_C' with the value 3.
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 command:
This way lies madness.
FoxPro has an #UNDEF 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
*-- This indicates that there are no entries here - it starts with a "-" so that
*-- it sorts to the head of any list. Similarly for all entries.
#DEFINE NOENTRIES "-None-"
#DEFINE ALLENTRIES "-All- "
*-- We need something more meaningful than .F. and .T. when displaying
*-- Boolean values.
#DEFINE APP_FALSE "False"
#DEFINE APP_TRUE "True"