<< Prev        Next >>

ID : 576

Local Variable

Local Variable is a variable which is named and created (declared) in PacScript program (task) by user.

Data Type, Number, Declaration of Local Variable

To use a local variable, you need to designate and declare a variable name according to naming convention after designating a type (data type) essential in PacScript. Declaration is essential for use of variable.

Declaration of local variable should be done by the following declaration statement.

Dim
Declare a local variable with no attribute.
Static
Declare a local variable with Static attribute.
Public
Declare a local variable with Public attribute. Static attribute will be added automatically.

You can use the following data type for declaration and array as well. However, an initial value cannot be set at the time of declaration in case of array.

Data type Data type keyword Remark
Integer type Integer
Single precision real number type Single
Double precision real number type Double
String type String Data size varies depending on with/without Static attribute.
Vector type Vector
Position type Position
Joint type Joint
Homogeneous translation type Trans
I/O type - Designate by DefIO. Neither Static nor Public attribute can be added.
Variant type Variant

<Example of description>

Dim aaa As Integer
Dim bbb(3) As Position
DefIO ccc = Bit, 128
Static ddd As Position = P(100,0,200,180,0,180,-1)
Public eee(9) As Integer

About a memory used

There are no limitations on the number of declaration you can use, but to avoid the memory shortage, declare only what you need.

Reserved memory type of local variable varies depending on the attribute.

A memory for local variable with no attribute declared in "Dim" is reserved in the working memory, created dynamically and will be released after the execution of a task or procedure.

A memory for local variable with "Static" or Static attribute declared in "Public" is reserved in the storage memory and the value will be retained even if the controller is turned off.

Refer to "Display of System Information (Controller Tab)" and "Display/Setting of the Number of Variable Used" to adjust the number of variables to avoid the memory shortage.

About Attribute

"Static" and "Public" attribute can be added to a local variable.

Static attribute

Static attribute is an attribute which can retain the value of a variable even if the controller is turned off. The declaration should be done in "Static" statement.

Public attribute

Public attribute is an attribute which allows other tasks to access a local variable through functions. The declaration should be done in "Public" statement. Static attribute will be added automatically.

Accessing and Valid Range (scope) of Local Variable

The valid range of local variable varies depending on the location where declaration is described. Refer to "Valid Range of Local Variable."

It should be described in a procedure
The declared local variable in the procedure will be created (initialized) at the time of procedure execution and will be deleted after the execution. This is accessible only from within the procedure. Static local variable cannot be declared.
It should be described in declarative part of program
A local variable described in declarative part of program will be created (initialized) at the time of task execution and will be deleted after the execution. However, Static local variable will be created (initialized) at the time of compiling and will be deleted when the program is deleted.

If there is no modification in a description of the Static local variable at the time of compiling, it will not be initialized. And, even one description of a Static local variable described in a program has been modified, all Static variables in the program will be initialized.

ID : 576

<< Prev        Next >>