Constants

23.04.2021

Constants used in FPScript are subject to specific syntax rules, where, based on the notation used, FlexPro can recognize the data type as well as the value.

Integers can be written in decimal, octal and hexadecimal notation. Octal numbers are written with a leading zero and can only contain the numbers 0 to 7. Hexadecimal numbers are writing with a leading combination 0x and can contain numbers 0 through 9 and A through F. Displaying hexadecimals and octals is interesting for digital data because there is a direct relationship between the numbers and the bits that represent them. For octal numbers, three bits are the equivalent of one digit, and with hexadecimal numbers, four bits are the equivalent of one digit. Please note that the only the notation is different for integers. Internally, all integers are saved in binary form.

FlexPro can process floating point values with 16-bit, 32-bit and 64-bit resolution. You can control the resolution by appending an 'S' or 's' for "short" or an 'L' or 'l' for "long". If you append the suffix 'N' or 'n', then this corresponds to 32-bit or 64-bit integers, depending on which format can store the constant.

Examples of 16-bit integers are:

123s

Decimal

0427s

Octal

0x1afs

Hexadecimal

Examples of 32-bit integers are:

100000n, 12n

Decimal

01024341121, 0123

Octal

0x10A00FF, 0x1A, 0x1a

Hexadecimal

Examples of 64-bit integers are:

10000000000n, 12L

Decimal

071024341121, 0123L

Octal

0x1010A00FF, 0x1AL, 0x1aL

Hexadecimal

Floating point values consist of a mantissa with whole and fractional digits and an optional exponent with a leading e or E. Floating point values can also be a void value. This value is displayed as ?.

FlexPro can process floating point values with 32-bit and 64-bit resolution. 32-bit floating point values are accurate to approximately seven decimal places, and 64-bit floating point values have are accurate to approximately 15 decimal places. You can control the resolution here as well by appending an 'S' or 's' for "short" or an 'L' or 'l' for "long". If you do not append a suffix, then this always corresponds to 64-bit floating point values, which means that the suffix 'L' can always be left off.

Note: For the FPScript code, the decimal point (.) is always the decimal symbol, even if in the Regional and Language Options settings of the Windows Control Panel you have specified the comma (,), which is commonly used in some European countries.

Examples of 32-bit floating point values are:

1.23s, 1.234e-12s, 1e+13s, 0.1e12s, 5.s, ?s

FlexPro does not recognize whether the range of values or the resolution has been exceeded. If you would like to obtain 64-bit floating point values, you need to omit the 's'.

Examples of 64-bit floating point values are:

1.23, 1.234e-12, 1e+13, 0.1e12L, 5.L, ?, ?L

In general, spaces may not be used within numbers, not even between mantissa and exponent. If an overflow occurs during a calculation, FlexPro cannot recognize this! You have to ensure that the range of values of the data type is sufficient to perform the calculation.

Example:

1000s * 1000s

Generates an overflow because the result, 1,000,000, does not fit into a 16-bit integer! (Solution: 1000n * 1000n)

Note: Interpreted like decimal numbers to which you have not added a suffix or decimal point, depending on whether the setting Interpret decimal numbers without a decimal point as floating point values is enabled on the General tab of the database properties dialog box. This option is enabled by default, which means that the numbers are interpreted as 64-bit floating point values. This setting prevents accidental rounding errors that may occur when using integer arithmetic. Integral division 1 / 2 results in 0 and not 0.5, for instance.

Complex numbers consist of a real and imaginary part, either in the form of a + bi or separated by commas and placed in parentheses. You can use all of the above notations for constants for the real part and the imaginary part. If this results in different data types for the real and imaginary parts, then these are adapted to each other before being combined into a complex number so that there is no loss of resolution. Within the FPScript, the comma (,) is always the list separator, even if in the Regional and Language Options settings of the Windows Control Panel you specified the semicolon (;), which is commonly used in some European countries.

Examples of complex numbers are:

(1.23s, 1.234e-12s) , (1e+13, 0x1), (5.L, ?), 1 + 2i, -3.2 - 7.6i, 5.2i, ?i, 2s + 5si

Strings are entered as text set off by quotation marks. There are specific control sequences available for special characters, such as a tab or a return character. These sequences all start with a '\' character.

Note: If you would like to use the '\' character as part of your text, you will have to include it in the string twice. The file path C:\Data.txt must be written as the string "C:\\Data.txt" for example.

Control sequence

Stands for

\b

Backspace

\f

Form feed

\n

New line

\r

Carriage return

\t

Horizontal tab

\v

Vertical tab

\'

Single quotation mark

\"

Double quotation mark

\\

Backslash

\oooooo

UNICODE characters in octal notation

\xhhhh

UNICODE characters in hexadecimal notation

Examples of strings are:

"A Text", "C:\\Data\\File.txt",", "Two\r\nlines"

The Empty data type can also be used as a constant to empty a variable used in a formula, for instance. To do this, just write Empty :

Result = Empty

Calendar time values consist of the date and time, with seconds in fractional digits being optional. Only three formats are allowed within FPScript. If you separate the date elements with '.', then the sequence will be Day.Month.Year, and if you use '/' as the separator, then this is interpreted as Month/Day/Year. If you use '-' as the separator, then it is interpreted as Year-Month-Day. The year can be entered as two or four digits. In the two-digit format, for values smaller than 70, 2000 is added, otherwise 1900 is added. For floating point data types, as well as for calendar times, the value is void if '?/?/?' appears. The elements for time are always specified in the format HH:MM:SS.ss. You can omit time elements starting from the right if they are zero. Constants in calendar time format must generally be written using single quotation marks:

Optionally, you can specify the time zone in which the calendar time value constant should be interpreted. To do this, append the time shift in hours from Universal Time Coordinated (UTC), e.g. "UTC+1". If you do not specify a time zone, the calendar time value constants are interpreted in local time, i.e. these are converted into the UTC format used for internal storage taking into account the time zone settings in Windows and, if applicable, daylight saving time.

'23.10.2004 12:13:24.123'

Calendar time value with a resolution of 1ms

'10/23/2011 12:13:24.123'

Calendar time value written in English notation with a resolution of 1ms

'2004-10-23 12:13:24.123'

Calendar time value arranged as Year-Month-Day

'23.10.2004 12'

Calendar time value 23.10.2004 at twelve noon

'23.10.2004'

Calendar time value 23.10.2004 at midnight

'1.1.24'

Calendar time value 1.1.2024 at midnight

'1.1.98'

Calendar time value 1.1.1998 at midnight

'?/?/?'

Invalid calendar time value

'1.2.2021 13:14'

1.2.2021, 13:14 in local time

'1.2.2021 13:14 UTC'

1.2.2021, 13:14 in Universal Time Coordinated (UTC)

'1.2.2021 13:14 UTC-2'

1.2.2021, 13:14 in UTC minus 2 hours

'1.2.2021 13:14 UTC+2:30' or '1.2.2021 13:14 UTC+2.5'

1.2.2021, 13:14 UTC plus 2 hours, 30 minutes

Time span values consist of the elements day, hour, minute, second. You can specify seconds using fractional digits as an option. The elements are specified in the format D:HH:MM:SS.ss. You do not have to specify all elements. If you specify two elements, then this is interpreted as HH:MM. If you specify three elements, then they are interpreted as HH:MM:SS, and four elements are then interpreted as D:HH:MM:SS. For output, FlexPro uses three or four elements as the standard. The day is omitted if the time span is less than 24 hours. Constants in calendar time format must generally be written using single quotation marks:

'12:13:24.123'

Time span value with a resolution of 1 ms

'13:24'

Time span value of 13 hours and 24 minutes

'2:01:30:00' or '49:30'

Time span value of 2 days, 1 hour and 30 minutes

'?:?:?'

Invalid time span value

Note: The calendar time and time span values have second as the implicit unit. The unit symbol, however, is not displayed.

Pre-defined constants

FPScript recognizes a series of pre-defined constants. The names of the constants cannot be used as object names or as variable names. These are mathematical constants PI = 3.141592654L and E = 2.718281828L as well as a series of constants that have pre-defined meaning as the parameters for functions.

You might be interested in these articles