Visual Basic and Visual FoxPro constants

VBA

Const

VFP

#DEFINE, #UNDEF, #INCLUDE

Visual Basic Syntax Notes

Constants in Visual Basic can be Private (the default) or Public and can optionally be defined as having a data type:

Public Const VAT_RATE As Single = 0.175

Visual Basic for Applications has a wide range of useful system constants such as vbBlue built into the language. Use the Object Browser from the View menu in the Visual Basic window to search for constants.

[VBA Object Browser]

Visual FoxPro Syntax Notes

Constants in Visual FoxPro are neither Public nor Private in the normal sense of the terms. They exist from the moment that they are created with #DEFINE until the moment that they are released with #UNDEF:

#DEFINE CTRL_C 3 * CTRL_C now exists in all * the lines of FoxPro code * which may be in several different modules * until it is undefined like this: #UNDEF CTRL_C

Do not try to put an '=' sign into the declaration of the constant.

Visual Foxpro include files

[Include constants in a Visual FoxPro class] FoxPro also has the #INCLUDE directive which pulls a header file of constants into the program. This makes maintenance easier because you can then keep all the constants for a project in one external file rather than having to cut and paste the #DEFINE statements into every module.

The FoxPro.H file supplied with the language includes the definitions of many useful constants such as COLOR_BLUE. Unlike Visual Basic, these are not built into the language itself.

A form or a class can also use a constant file. Rather than using the #INCLUDE statement you select Include File... from the Class or Form menu as appropriate. You can also set up the FoxPro options to specify a default include file.

It is possible to chain these include statements so that a project may have an include file which itself pulls in the standard FoxPro.H:

#INCLUDE FoxPro.H

*-- 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"

Comments  |  Language index  |  Variables

Related Items

VFP and VBA.

The Visual FoxPro and Visual Basic for Applications languages are similar but there are annoying differences between them.

Read More

Text delimiters in VBA and VFP.

Visual Basic for Applications and Visual FoxPro delimiters for strings.

Read More

Text concatenation in VBA and VFP

Visual Basic for Applications and Visual FoxPro operators to concatenate text.

Read More

Text substrings in VBA and VFP

Visual Basic for Applications and Visual FoxPro functions to extract substrings from within a string of text

Read More

Trimming text in VBA and VFP

Visual Basic for Applications and Visual FoxPro functions to trim leading and trailing spaces from string of text

Read More