4D v16.3

Constants

Home

 
4D v16.3
Constants

Constants  


 

 

A constant is an expression that has a fixed value. There are two types of constants: predefined constants that you select by name, and literal constants for which you type the actual value.

4D provides a set of predefined constants. These constants are grouped by themes in the Explorer Window:

To use a predefined constant in a Method editor window:

  • Drag and drop the constant from the Explorer window to the Method editor window.
  • Directly type its name in the Method editor window. The autocomplete mechanism suggests constants that correspond to the programming context.

Predefined constants appeared underlined by default within the Method Editor and Debugger windows:

In the window shown here, On Load, for example, is a predefined constant.

Literal Constants can be of four data types:

  • String
  • Numeric
  • Date
  • Time

A string constant is enclosed in double, straight quotation marks ("…"). Here are some examples of string constants:

"Add Records"
"No records found."
"Invoice"

An empty string is specified by two quotation marks with nothing between them ("").

A numeric constant is written as a real number. Here are some examples of numeric constants:

27
123.76
0.0076

Negative numbers are specified with the minus sign(–). For example:

–27
–123.76
–0.0076

Note: Since 4D v15, the default decimal separator is a period (.), regardless of the system language. If you have checked the "Use regional system settings" option (see Methods Page), you must use the separator defined in your system.

A date constant is enclosed by exclamation marks (!…!). Since 4D v15, a date must be structured using the ISO format (!YYYY-MM-DD!). Here are some examples of date constants:

!1976-01-01!
!2004-09-29!
!2015-12-31!

A null date is specified by !00-00-00!.

Tip: The Method Editor includes a shortcut for entering a null date. To type a null date, enter the exclamation (!) character and press Enter.

Notes:

  • For compatibility reasons, 4D accepts two-digit years to be entered. A two-digit year is assumed to be in the 20th or 21st century based on whether it is greater or less than 30, unless this default setting has been changed using the SET DEFAULT CENTURY command.
  • If you have checked the "Use regional system settings" option (see Methods Page), you must use the date format defined in your system. Generally, in a US environment, dates are entered in the form month/day/year, with a slash "/" separating the values.

A time constant is enclosed by question marks (?...?).

In the US English version of 4D, a time constant is ordered hour:minute:second, with a colon (:) setting off each part. Times are specified in 24-hour format.

Here are some examples of time constants:

?00:00:00? ` midnight
?09:30:00? ` 9:30 am
?13:01:59? ` 1 pm, 1 minute, and 59 seconds

A null time is specified by ?00:00:00?

Tip: The Method Editor includes a shortcut for entering a null time. To type a null time, enter the question mark (?) character and press Enter.



See also 

Control Flow
Data Types
Identifiers
Methods
Operators
Pointers
Variables

 
PROPERTIES 

Product: 4D
Theme: Language definition

 
HISTORY 

Modified: 4D v15

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)