You are here: Function Reference > Alphabetical Listing > D > DECLARE

DECLARE

Use this function to create a DAL variable as an integer variable, decimal variable, or string variable and optionally assign it a code page value.

Syntax

DECLARE("Variablename", Codepage, Convert)

Parameter

Description

Variable name

Enter the string constant or variable.

Codepage

(Optional) Enter the code page value that you want the variable to use.

You can choose from these code pages:

  • 1250 — Central and East European Latin
  • 1251 — Cyrillic
  • 1252 — West European Latin
  • 1253 — Greek
  • 1254 — Turkish
  • 1257 — Baltic
  • 65001 — Unicode (UTF-8 encoded )

If no CodePage and Locale values have been set, the system will use a default value of 1252. Code page 1252 is a character encoding of the Latin alphabet that represents English and Western European languages.

Convert

If the declared variable exists and contains a value, this value will be converted to the newly defined code page.

If you do not want to convert this value, then set this parameter to 0.

Variable Types

Variable Name Type Variable name starts with a

Example

Creates a...

Notes
integer #

DECLARE("#MyVar")

integer variable called #MyVar. Integer variables receive whole number values,
for example, #Employees = 3000
decimal $

DECLARE("$MyVar")

decimal variable called $MyVar

Decimal variables receive numeric values with decimals,
for example $BEGIN_BALANCE = 100.00
string letter DECLARE("MyVar") string variable called MyVar which will use the default code page

String variables receive text data and text containing
characters from a specific Windows code page, for example:

RUSSIANVARIABLE = 'Это текст на русском языке'

Example: Using a Code Page Value

DECLARE("MyVar", 1253) would create a string variable called MyVar which would use code page value of 1253.

Note that the first parameter will normally be a quoted string that names the variable. If your parameter is a DAL variable (without quotes), then the contents of that DAL variable are used.

For example, assume you had these statements:

MyVar = "XYZ"
Declare(MyVar, 65001)

Because the parameter supplied to the Declare function is a DAL variable and not a quoted string, these statements create a new DAL variable named XYZ that uses code page 65001. The DAL variable MyVar is not affected by this Declare statement.

Example: Converting Contents

If the variable you want to declare exists, then this new declaration will first convert the existing content to Unicode and then convert it to the requested code page in an attempt to map the characters to that code page. Note that code pages do not contain all the same characters.

If a character from the original code page declaration is not defined in the desired code page, then that character is replaced with a question mark (?) after the conversion.

If you do not want to convert the contents when re-declaring a variable, use 0 as the third parameter.

For example:

DECLARE(“AVariable”, 1252)
AVariable = “ÀÈÏÒÚ”
DECLARE(“AVariable”, 1253, 0)

In this example, the variable AVariable was first declared as 1252, then assigned text that is supported by that code page. The final statement instructs the variable to use code page 1253, the single-byte Greek code page.

If you omit the third parameter (0), then the second declaration would attempt to convert the existing text to the stated code page. The resulting conversion would appear as"???Ò?" because most of the characters from the original text are not defined in the 1253 code page. However, because this example specifies 0 in the third parameter, no conversion occurs when the code page is changed. An entirely different string will appear that happens to use the same code points as the original code page.

Important It is important to understand this process if you try to change a previously declared Unicode (65001) variable to a single-byte code page without first converting it. UTF-8 can use multiple physical character bytes to represent a single code point. Therefore, changing this UTF-8 variable to a single-byte code page without first converting it could yield a strange text string that is longer than the original text.

See Also