Data Types
Navigation: PGMs ➔ PGM Programming and Conventions ➔ Data Types
PGM Syntax | Data Types | Declaring Variables | Predefined Variables | Formatting |
---|
Summary Table of Data Types
The variable types supported by the PGM are shown below. See also Variable declaration.
Type Name | Value Type | Range of Values | Displayed As | Notes |
---|---|---|---|---|
Real Numbers | ||||
REAL | Real | -1.0 E308 to 1.0 E308 | Value with decimal points, or * if NAN | Use IsNAN function to test for NAN |
DOUBLE | Real | -1.0 E308 to 1.0 E308 | Value with decimal points, or * if NAN | Use IsNAN function to test for NAN |
Integers | ||||
INTEGER | Integer | -2147483648 to 2147483647 | Integer | |
LONG | Integer | -2147483648 to 2147483647 | Integer | |
INT | Integer | -2147483648 to 2147483647 | Integer | Available from Build 139.32217. |
BYTE | Integer | 0 to 255 | Integer | |
Enum | Integer | Usually starts at 0 | Creates a list of integer constants. | |
EnumDropList | Integer | Usually starts at 0 | A drop down list with enum list of integer constants. | |
DropList | Integer | Usually starts at 0 | A drop down list, each with an associated integer value | |
Boolean Numbers | ||||
BIT | Boolean | FALSE = 0; TRUE <> 0 | 0 (False); 1 (True) | |
BOOL | Boolean | FALSE = 0; TRUE <> 0 | 0 (False); 1 (True) | Available from Build 139.32217. |
BOOLEAN | Boolean | FALSE = 0; TRUE <> 0 | 0 (False); 1 (True) | Available from Build 139.32217. |
CheckBox | Boolean | FALSE = 0; TRUE <> 0 | Tickbox | |
Alphanumeric Values, or Strings | ||||
STRING | String | ASCII Character Set; | Words (unlimited length) | |
STR | String | ASCII Character Set; | Words (unlimited length) | |
MEMO | String | ASCII Character Set; | Words (unlimited length) | Scrolls onto multiple lines as required |
Notes:
- Variable names must be alphanumeric and uniquely declared within their current scope. See Variable Declaration Rules for a full description.
- The PGM language, including variable naming, is NOT case sensitive.
- Only variables of type Double or Real can have a value of NAN (Not a Number) shown as a '*' on the Access window. Use IsNAN function to test for NAN.
- When a value or variable is assigned to another variable, it is ranged within the new variable type's range, as illustrated in the examples below.
Examples (showing ranging based on Data Type)
INTEGER w
BIT i
BYTE z
z = 1035 ;z = 255 maximum value of Byte type is 255.
z = -2.3 ;z = 0 minimum value of Byte type is 0.
z = 5.6 ;z = 5 byte can only be integer, it takes the first digit
w = 1.3e12 ;w = 2147483647 maximum value of Long type
w = NAN ;w = -2147483648 not a number, assigned with the minimum value of type
w = 335.4 ;w = 335 INTEGER type are integers only.
z = w ;z = 255 limited by the maximum value of byte type.
i = 0.1 ;i = 1 (true) Bit is true if i ≠ 0
i = 12 ;i = 1 (true) Bit is true if i ≠ 0
i = -3 ;i = 1 (true) Bit is true if i ≠ 0
i = 0.0 ;i = 0 (false) Bit is false if i = 0
User Defined Constants using the Const Keyword
Syntax:
- Const TYPE variable = value OR
- Const TYPE variable = Predefined Molecular Weight Function
A const Array, Matrix or StrArray class can also be declared. Available from Build 139.32335. For example:
const Array SomePrimes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71}
const Matrix Table1 = { {2, 5, 10}, {1, 3, 6} }
const StrArray Rainbow = { "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet" }
The Const keyword ensures that the value assigned to the variable will remain unchanged (i.e. it becomes a read only variable). See also Predefined Constants and Variables.
Examples
Const real OreDensity = 5000
Const real LiquidHTC = 1.5 ;Numbers cannot be written as a fraction.
Const real MW_NaCl = MW("NaCl")
Const real MW_H2SO4 = MW("H2SO4")
Const integer Auto = 1
Const long Manual = 2
Const bit Running = 1
Const bit Stopped = 0
Const String Condition1 = "Mass balanced"
Const String Condition2 = "Mass NOT balanced"
const real MaxFlow@ = 1300 ; available in Build 139.32530 or later, allows use of @ or @@ when declaring const variables.
NOTES:
- A Constant variable is always added to global scope even if it is declared within a function or class function. It is accessible in code outside of the function where the const was declared.
- A Constant variable cannot be declared in a Class.
- A Constant variable can be displayed in the Access window using Watch.
- A Constant variable cannot be a calculation, this includes using numbers in fractions. So while const Real LiquidHTC = 1.5 will work, LiquidHTC = 3/2 will report an error.
- Constant variables cannot be changed, so they can only be appended with @ or @@ when declaring const variables. Available from Build 139.32530.
Check Box
The user can add a check box to the access window by declaring the variable as type Checkbox. The check box is a toggle between true(1) and false(0).
See Declaring Variables.
Integer variables as Enum
An Enum (derived from Enumerate) is an Integer (or Long) data type. The use of Enum is a convenient method to declare a number of integer constants by name. Then use these named constants throughout the code instead of integer values. Code is then significantly easier to follow and maintain.
Note:
- The user cannot display the Enum constants in the Access window.
- The names in the Enum list need to be globally unique.
- The declaration cannot occur within a class, but the declared constants can be used within a class. (See Example : using Enum Drop list and Drop List in a class)
- As Enum types are simply a synonym for data type Integer. This allows you to declare variables with the named enum type, see definition of Colour_Choice in example.
- As the underlying data type is simply an integer, there is no enforced validation of the integer value to be limited to the available values in enum list. Use EnumDropList for this purpose.
Enum Drop Down List
The user can add a Drop Down List to the access window by declaring a variable of type EnumDropList. In addition to creating the drop down list the variables are also constant enum integers. The use of named constants throughout the code instead of integer values, makes the PGM code significantly easier to follow and maintain. The use of an EnumDropList is best shown in an example:
Enum Drop Down List Example EnumDropList Options{Acid=2, Basic=4, Neutral}
Options Act_Mode@, Req_Mode*
string ModeDesc@
Act_Mode = Basic
ModeDesc = StrCat("Mixture mode is ", EnumStr(Act_Mode))
if (Act_Mode==Neutral)
;Some code here
endif
|
This will be displayed in the Access window as follows: |
Notes:
- The initial (default) value of the variable is the first item in the list. In the above example Req_Mode will initially be 2 (Acid).
- Unlike the simple Enum declaration, if the variable is set to a value which doesn't match one of the defined options, SysCAD will choose the option which is numerically the closest.
- In the above example, if Act_Mode is set to 3, SysCAD will reset its value to 2 (Acid).
- Each item in the EnumDropList has an integer value.
- The names in the EnumDropList list need to be globally unique.
- If the user does not set a value, then counting is automatic, starting at 0 and incrementing by 1.
- However, the user may override the automatic values and assign their own values to the variables, as shown in the above example. In this case, if a variable is NOT assigned a value, then its value is incremented by 1 from the previous variable.
- The EnumStr function can be used to return the current value of the variable as a string. Useful for feedback messages, etc.
- The definition of the drop-down list (using data type EnumDropList) cannot occur within a class, but EnumDropList defined outside of the class can be used for variable declaration within a class. See Example : using Enum Drop list and Drop List in a class.
Drop Down List
The user can add a Drop Down List to the access window by declaring a variable of type DropList. It is more common to use EnumDropList. The variable will be of type Integer. (Note that Enum Drop Down List allows the user to override the automatic sequential values and assign their own values to the variables, whereas Drop Down List variables will always be an integer value starting at 0 and incrementing by 1). Drop Down List is best shown in an example:
Drop Down List Example DropList Options{"Acid", "Basic", "Neutral"}
Options Act_Mode@, Req_Mode*
Act_Mode = 1
if (Act_Mode==2)
;Some code here
endif
|
This will be displayed in the Access window as follows: |
Notes:
- Each item shown in the Drop Down List has an integer value starting at 0 and incrementing.
- In the image above, if the user selects 'Acid' in the Req_Mode droplist, then Req_Mode = 0, if 'Basic' is selected, then Req_Mode = 1 and similarly if 'Neutral' is selected, then Req_Mode = 2.
- Please note that when using the drop list in the PGM logic, user cannot use the string, e.g.: "Act_Mode = Acid", the integer should be used, e.g.: "Act_Mode = 0". To use "Act_Mode = Acid", then the droplist must be defined as 'EnumDropList'.
- The initial (default) value of the variable is 0, corresponding to Acid, the first item in the list.
- User can also override the values, see example below
- If the variable is set to a value which doesn't match one of the defined options, SysCAD will choose the option which is numerically the closest.
- In the above example, if Req_Mode is set to 4, SysCAD will reset its value to 2 (Neutral).
- The definition of the drop-down list (using data type DropList) cannot occur within a class, but DropList defined outside of the class can be used for variable declaration within a class. See example below.
Example : using Enum Drop list and Drop List in a class
This example shows the difference in Droplist and EnumDropList definition and usage. In general, the EnumDropList is commonly used.
DropList UnitOp{"Ready"=1, "InUse"=4, "Fault"=7, "Maint_Shutdown"=8} ;text strings are enclosed in double quotes, user defined integer values are optional
;DropList UnitOp{"Ready", "InUse", "Fault", "Maint_Shutdown"}
EnumDropList EnumUnitOp{Ready=1, InUse=4, Fault=7, Maint_Shutdown=8} ;text strings do not have quotes, user defined integer values are optional
;EnumDropList EnumUnitOp{Ready, InUse, Fault, Maint_Shutdown}
Class Class_EvalPlant
;using pre-defined DropList
UnitOp Unit_Operation_State@
EnumUnitOp Unit_Operation_State_Enum1@, Unit_Operation_State_Enum2@
string State_Description1@,State_Description2@
;place code here
EndClass
PageLabel "UnitOp"
TextBreak
Class_EvalPlant Tank1
;Using DropList options - integer value is required
Tank1.Unit_Operation_State = 7
;Using EnumDropList Options, string or integer can be used
Tank1.Unit_Operation_State_Enum1 = Maint_Shutdown ;OR
Tank1.Unit_Operation_State_Enum2 = 4
Tank1.State_Description1 = Concatenate("Current state is ", EnumStr(Tank1.Unit_Operation_State_Enum1))
Tank1.State_Description2 = Concatenate("Current state is ", EnumStr(Tank1.Unit_Operation_State_Enum2))
$
The left image shows the drop-down list using user defined integer values (from the above example), the right image shows the drop-down list using default values (no user value defined when declaring the droplist (as per line 2 and 4 in the above example, these were shown as comments, not in use).