Define
See Also: Array Types, Structured Types, Enum_List, #IFDEF, #REPLACE
Purpose
To create or rename compiler variables, and to assign values to them.
Syntax
Define {new-symbol}
Define {new-symbol} For {old-symbol}
Where {new-symbol} may be between 1 and 4096 characters in length, must start with a letter, and may not contain spaces. Recommended characters are 0-9, a-z, A-Z, and _ (underscore).
What It Does
Define allows you to create one or more compiler symbols for constant values.
The For phrase allows you to set a value of any data type for the symbol {new-symbol}:
Define C_StringOne for "One" // string
Define C_StartDate for 03/01/2020 // date
Define C_Pi for 3.14159265359 // number
When used outside an Enum_List / End_Enum_List pair and without the For clause, Define assigns an integer value of 1:
Define C_Test1 // value = 1
Define C_Test2 // value = 1
Define C_Test3 // value = 1
// ...
When surrounded by an Enum_List / End_Enum_List pair:
- Define assigns a symbolic replacement for a sequential series of constant values for as many
{new-symbol}s as are named in the command block.
When used without the For clause, Define assigns an integer value of 0 and increments the value of subsequent symbols defined by 1:
Enum_List
Define C_Test1 // value = 0
Define C_Test2 // value = 1
Define C_Test3 // value = 2
// ...
End_Enum_List
Example
The following example shows how the definition of a symbol can be used to change program behavior.
// To change the program comment out the next line.
Define C_EvaluationVersion
Define C_EvaluationAllowedSaves For 1000
Object oEvalTester is a Button
Function CheckEvalSave Integer iTotalRecords Returns Integer
// Conditional compilation.
#IFDEF C_EvaluationVersion
// Test record count versus evaluation limit.
If (iTotalRecords <= C_EvaluationAllowedSaves) Function_Return True
Else Function_Return False
#ELSE
Function_Return True // Allow all saves.
#ENDIF
End_Function
Procedure OnClick
Integer bEvalTest
Get CheckEvalSave To bEvalTest 500
Showln "500 saves = " bEvalTest
Get CheckEvalSave To bEvalTest 1500
Showln "1500 saves = " bEvalTest
End_Procedure
End_Object
In the above example, when the symbol C_EvaluationVersion is defined, evaluation restrictions are enabled in the program. Another symbol defines the limit for evaluation saves.
Enum_List // _htmlControlAlign
Define htmlControlAlignNotSet
Define htmlControlAlignLeft
Define htmlControlAlignCenter
Define htmlControlAlignRight
Define htmlControlAlignTextTop
Define htmlControlAlignAbsMiddle
Define htmlControlAlignBaseline
Define htmlControlAlignAbsBottom
Define htmlControlAlignBottom
Define htmlControlAlignMiddle
Define htmlControlAlignTop
Define htmlControlAlign_Max For 2147483647
End_Enum_List
Object oTest Is A Button
Procedure OnClick
Showln "These are some HTML Control Alignment Variables..."
Showln "Alignment not set: " htmlControlAlignNotSet
Showln "Right Alignment: " htmlControlAlignRight
Showln "Top Alignment: " htmlControlAlignTop
Showln "Max value: " htmlControlAlign_Max
End_Procedure
End_Object
Notes
- Note that the Define command creates no program overhead. You may use Define freely to make your program more readable.
- Use it to simplify your program logic by giving meaningful names to your system constants.
- Define is also useful for representing external component interface constants.
- When
Foris used with the Define command in an enumeration list to assign a constant value, enumeration continues sequentially from the value given in subsequent Define commands.