A variable holds a value that you can use and change throughout your code so long as the variable is within scope. With variable declaration, you not only want to know the syntax of how you declare a variable but you also want to know where. Are you allowed to declare a variable inline? What are the available scopes: local vs. global. Can you assign a value at the same time you declare a variable?
ObjectPAL Variables
Declaring variables is optional unless you click Program | Compiler Warnings while in the ObjectPAL editor for every form, script, and library you create. Using Compiler Warnings is strongly recommended to avoid incorrectly typing an existing variable and to avoid any confusion about variable scope. Also recommended is turning on Compile with Debug for every form, script, and library too for tighter, cleaner code.
Undeclared variables are AnyType variables. Common data types include Currency, Date, Datetime, Logical, LongInt, Number, SmallInt, String, and Time.
Syntax Example:
var FullName String Age SmallInt Weight Number
endVar
FullName = "Mike Prestwood" Age = 32 Weight =154.4
msgInfo("", FullName + ", age=" + String(Age)
+ ", weight=" + String(Weight))
Declare local variables within a method. If you want a local static variable (retains it's value because it is not destroyed), declare the variables above the method. Variables declared in an object's Var window are visible to all methods attached to that object, and objects that it contains.
The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.