Article ID: 131475
Article Last Modified on 2/15/2000
#DEFINE CANCELENTRY "Are you sure you want to cancel this record?"Then, use CANCELENTRY in your Visual FoxPro code. To translate your program for a different country, all you need to do is translate a copy of the constants file into the different language. No changes to your Visual FoxPro code are necessary.
* COMMON.H *-- ASCII #DEFINE LF CHR(10) #DEFINE CR CHR(13) #DEFINE CRLF CR+LFIf you use #INCLUDE to include this COMMON.H file in your Visual FoxPro project, you can use the text CRLF at any point in your program code where a carriage return/linefeed combination is needed. You no longer need to type CHR(13)+CHR(10). While either choice (CRLF or CHR(13)+CHR(10)) is valid, if a defined constant should change values, it need only be changed in a single location for that change to be reflected at all locations in your code where the constant is referenced.
*-----------------------------------------------------------*
* Sample program : TESTFILE.PRG *
*-----------------------------------------------------------*
#INCLUDE "COMMON.H" && Use definitions from COMMON.H file
ACTIVATE SCREEN
CLEAR
? 'Line 1'+CRLF+'Line 2'
=TestUDF()
FUNCTION TestUDF
? DRAG_ENTER && refer to FOXPRO.H file
RETURN
*-----------------------------------------------------------*
*-----------------------------------------------------------*
* Sample Header File: COMMON.H *
*-----------------------------------------------------------*
*-- ASCII
#DEFINE LF CHR(10)
#DEFINE CR CHR(13)
#DEFINE CRLF CR+LF
*-- Header files
#INCLUDE "FOXPRO.H" ** If not in current directory, you
** must qualify this file with the
** appropriate path location
*----------------------------------------------------------*
*-- Function Parameters *-- MessageBox parameters #DEFINE MB_YESNO 4 && Yes and No buttons #DEFINE MB_ICONQUESTION 32 && Warning query #DEFINE MB_DEFBUTTON2 256 && Second button is default *-- MsgBox return values #DEFINE IDYES 6 && Yes button pressed #DEFINE IDNO 7 && No button pressedGiven the above definitions, a sample dialog box written without the named constants might read as follows:
cMessageTitle = 'My App'
cMessageText = 'Record not found. Would you like to search again?'
nDialogType = 4 + 32 + 256 && The appearance of the message box
* 4 = Yes and No buttons
* 32 = Question mark icon
* 256 = Second button is default
nAnswer = MESSAGEBOX(cMessageText, nDialogType, cMessageTitle)
IF (nAsnswer = 6) && Yes was selected
&& Execute some other code
ENDIF
The nDialogType code could be recast using named constants as this:
cMessageTitle = 'My App'
cMessageText = 'Record not found. Would you like to search again?'
nDialogType = MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2
nAnswer = MESSAGEBOX(cMessageText, nDialogType, cMessageTitle)
IF (nAnswer=IDYES)
&& Execute some other code
ENDIF
Both ways are equally valid, but by using words as opposed to numbers, the
code is easier to understand and maintain.
Additional query words: VFoxWin Preprocessor
Keywords: kbcode KB131475