Variable functions

Completed

When you run code in Business Central, variables are initialized the first time with their default value.

You might want to reinitialize them on occasions when you're working in a loop and need the variables to have their default values.

Variable functions include:

  • Clear

  • ClearAll

When you're working with variables, each with a different data type, and you want to assign a value from one data type to another, use the automatic type conversions. If this option isn't possible, use the following functions:

  • Evaluate

  • Format

Clear and ClearAll functions

The Clear function helps you clear or reset a variable. This function will reinitialize the default value to the variable.

var
   myText: Text[20];

myText := UserId;
Clear(myText);      // Sets the variable myText to an empty string.

The ClearAll function resets all variables (except the Rec variable) to their default values. It also clears all keys and filters that have been set.

Evaluate function

You can use the Evaluate function to convert a variable of data type text (code or text) to another data type (that is not text).

<Boolean> := Evaluate(<variable>, <Text to convert>)
var
   myText: Text[20];
   myInteger: Integer;

myText := '5';
Evaluate(myInteger, myText);

Format function

The Format function converts a data type to a text data type.

<String> := Format(<variable>)
var
   myText: Text[20];
   myInteger: Integer;

myInteger := 3;
myText := Format(myInteger);