A variable must be declared (created) before you can use it in Crystal.
A variable can hold values of a given type. Allowed types are: Number, Currency, String, Boolean, Date, Time and DateTime. The range types are Number Range, Currency Range, String Range, Date Range, Time Range and DateTime Range). Variables can also be declared for ones that hold arrays of the previously mentioned types.
You must specify a variable’s name when you declare it. A variable cannot have the same name as any function, operator or other keyword that is valid for Crystal syntax. For example, your variable cannot be named Sin, Mod or If because Sin is a built in function, Mod is a built in operator and If is a built in keyword. Once a variable is declared, it can be used in the formula.
For example, assign a varible a specific value or number:
Local NumberVar x; //Declares x to be a Number variable
x := 10; //Assigns the value of 10 to x
Note: The keyword for declaring the Number variable has a Var at the end. This is true for all the variable types in Crystal syntax.
A variable can only hold values of one type. For example, if a variable holds a Number value, you cannot later use it to hold a String.
Examples of declaring and initializing range variables:
Local NumberVar Range topsales;
Local DateVar Range quarter;
topsales := 5000 To 100000;
quarter := CDate (1999, 10, 1) To CDate (1999, 12, 31);
-- by Gayle Raines, Director of Training at Baytek, an Authorized Peachtree Resource Center.