Variable

From GAB Help
Jump to: navigation, search

Definition

Variables used in Subroutines fall into two categories: those that are explicitly created within the subroutine and those that are not. Variables that are explicitly created in a subroutine (using Declare or Static) are always local to the subroutine. Variables that are used but not explicitly declared in a subroutine are also local unless they are explicitly declared at some higher level outside the subroutine.

Variable Types

Static - Used within the current subroutine; they keep their value through multiple calls to the same sub.

Local - Used within the current subroutine and initialize with each call to the subroutine, if the variable is a number it returns to zero, if a string it becomes blank again.

Global - Can be called in any subroutine not just the current; the value can be modified or read in any subroutine.

Additional Types - Ambient, Args, Caller, Color, ODBC, Passed, Printer, Screen, System

Syntax

Local and Static variables should always be declared at the beginning of a subroutine

Variable.local.variablename.declare (data type) 

Data Types are Boolean, Date, Float, Long, and String

Global variables are created using the menu in GAB Editor. On the tool bar, go to Tools> Add Global Editor. This will prompt for the variable name and type.

Variable.Global.variablename.declare(date type)

The 653 version of OCTSRS.EXE now supports implied variable type declaration. If the variable type is ommitted, it will be assumed to be dictated by the leading character of the variable name. This is intended to nake the coding process faster for programmers that use variants of Hungarian naming conventions.

Supported prefixes and their equivalent data types

f = Float

l or i = Long

b = Boolean

d = Date

s = String

This feature cannot be used in conjunction with setting the initial value of the variable

Example

Static/Local:

Variable.local.sText.declare(String) 

Global:

Variable.Global.fSum.declare(Float) 

When Variables are declared storage space is allocated.

Naming a Variable

When naming a variable it is good to use a standardized naming convention, we at GS use a derivative of the Hungarian Naming Convention (See Naming Conventions). This convention only dictates the prefix. You should assign a meaningful name to the variable for code legibility.

Passed Variables

Variables coming from the Global Shop screens or processing data coming from the calling program come in through the passed variable name space. Passed variables can be set just like local and global variables, but additional information can be accessed.

Hwnd - Window handle

Type - What data type is the data coming across

MaxLength - Max characters allowed

IID - International ID

A special passed variable called v.passed.77777 is used to set the override flag. This will allow processes such as saving an order line be halted.

Setting passed variables for screens will only take affect if the script is running synchronous.