<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://help.syscad.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Eleanor.McFeaters</id>
	<title>SysCAD Documentation - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://help.syscad.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Eleanor.McFeaters"/>
	<link rel="alternate" type="text/html" href="https://help.syscad.net/Special:Contributions/Eleanor.McFeaters"/>
	<updated>2026-06-04T03:32:54Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.4</generator>
	<entry>
		<id>https://help.syscad.net/index.php?title=Save_Project&amp;diff=82178</id>
		<title>Save Project</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Save_Project&amp;diff=82178"/>
		<updated>2025-06-02T23:08:06Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Save Project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:User Interface]] [[Category:Project Files]]&lt;br /&gt;
{{Navigation|[[User Guide]]|[[Menu Commands]]|[[Project Command Summary|Project]]}}&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
{{TOC}}&lt;br /&gt;
== Save Project ==&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
|Command Button || [[Image:Save.png]] &lt;br /&gt;
|-&lt;br /&gt;
|Command Path || &#039;&#039;Project - Save Project&#039;&#039;  OR &#039;&#039;Project - Save&#039;&#039; in earlier builds&lt;br /&gt;
|-&lt;br /&gt;
|Shortcut Key || &#039;&#039;Ctrl+S&#039;&#039;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* This is used to save the project.&lt;br /&gt;
* This action will save the entire project using the existing project name overwriting the existing data.  &lt;br /&gt;
* If you wish to save to a new project name use the Project [[#Save As|Save As]] or [[#Save Version| Save Version]] command.  &lt;br /&gt;
* Before closing a project or exiting SysCAD, you will be prompted to save the project.  &lt;br /&gt;
* A project save cannot be performed if SysCAD is running or solving. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;u&amp;gt;Hint:&amp;lt;/u&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A project should be saved regularly to avoid loss of information during building of a new project or when making major changes to existing projects.&lt;br /&gt;
&lt;br /&gt;
== Save As ==&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
|Command Path || &#039;&#039;Project - Save As&#039;&#039;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* A project save cannot be performed if SysCAD is running or solving.&lt;br /&gt;
* This command saves the entire project in a new project folder and copies all referenced files if requested.&lt;br /&gt;
* With the project save as dialog box opened, find the correct folder to put the new project and type in a name for the project.  Press &#039;&#039;&#039;Save&#039;&#039;&#039;.&lt;br /&gt;
* A &#039;&#039;&#039;Project Save Options&#039;&#039;&#039; dialog box will be opened requesting for user input on what referenced files to copy if present.  See [[#Save Version|Save Version]] for the various options.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;u&amp;gt;Caution:&amp;lt;/u&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
*Make sure to choose a correct location for the new project folder, as this will help with file management.&lt;br /&gt;
*You cannot &#039;Save As&#039; to the current project location. Use &#039;Save Project&#039;, or &#039;Save As&#039;/&#039;Save Version&#039; with a different name.&lt;br /&gt;
&lt;br /&gt;
==  Save Version ==&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
|Command Button || [[Image:SaveVersion.png]] &lt;br /&gt;
|-&lt;br /&gt;
|Command Path || &#039;&#039;Project - Save Version&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Shortcut Key || &#039;&#039;Ctrl+Shift+S&#039;&#039;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* This cannot be performed if SysCAD is running or solving.&lt;br /&gt;
* This command saves the project with a version number.&lt;br /&gt;
* This command is similar to the Project Save As... command with only one exception.  Part of the file name will be prefixed with the old project name.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;For Example&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
If you have project - &#039;&#039;&#039;&#039;&#039;Tut_Test.spf&#039;&#039;&#039;&#039;&#039; opened and want to save with the &#039;&#039;Save Version&#039;&#039; command.&lt;br /&gt;
&lt;br /&gt;
You will be presented with the &#039;&#039;&#039;Project Save Options&#039;&#039;&#039; dialog box:&lt;br /&gt;
&lt;br /&gt;
:[[Image:Project Save Options.png]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Comment&#039;&#039;&#039;&lt;br /&gt;
* If a Comment Description is entered as shown in the picture above, the New Project will then be saved in a folder &#039;&#039;&#039;&#039;&#039;Tut_Test(3 Washing Stages)-01.spf&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
* Alternatively, if you leave this &#039;&#039;&#039;Comment text&#039;&#039;&#039; blank and press OK, your new project will be saved in a folder called &#039;&#039;&#039;&#039;&#039;Tut_Test-00.spf&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
* If this is saved again with &#039;&#039;Save Version&#039;&#039; the new project will be called &#039;&#039;&#039;&#039;&#039;Tut_Test-01.spf&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Database Options&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;Remove Previous Revisions&#039;&#039; - This allows the user to specify the ModelData.db3 save options.  (File in which SysCAD stores all the models information.) The global default for this option can be set via Tools - [[General Options Project | General Options - Project]].&lt;br /&gt;
*: NOTE: It is recommended to select the &#039;&#039;&#039;Remove Previous Revision&#039;&#039;&#039; Option to keep the database small and more accessible.  This will also shorten the save and load times.&lt;br /&gt;
* &#039;&#039;Save Object Files (extra state/result info)&#039;&#039; - This option is only useful for dynamic project, it allows user to save extra results and state in a separate folder called ObjectFiles. In these files, the initial conditions and state of dynamic models such as Layer tanks, conveyor belts etc. are saved. For Steady State Projects, this option is not needed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Additional files to be copied from the project folder&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
By default, all used (referenced) Report/Scenario/Script/Reaction/Control/ModelProcedure/etc. files will automatically copied into the new project folder.  If the old project folder contains any of the above file types that are not being used by the project, they can be included in copy to the new project folder by selecting the appropriate boxes.&lt;br /&gt;
&lt;br /&gt;
Other filetypes may also be added to the [[Excel Reports]] dialogue so that they are copied on save.&lt;br /&gt;
&lt;br /&gt;
== Save Layout ==&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
|Command Path || &#039;&#039;Project - Save Layout&#039;&#039;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* This will save the position and size of all the windows as well as the position and arrangement of the toolbars.  &lt;br /&gt;
* The layout is automatically saved when a project is saved.  &lt;br /&gt;
* This command is useful if you want to save the layout of the project without saving the entire project.&lt;br /&gt;
&lt;br /&gt;
==  Save/Rename As (Graphics) ==&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
|Command Path || &#039;&#039;Graphic - Save/Rename As&#039;&#039;   &lt;br /&gt;
|-&lt;br /&gt;
|Shortcut Key || &#039;&#039;Ctrl+Shift+A&#039;&#039;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This command is only available if the active window is a graphics window.&lt;br /&gt;
&lt;br /&gt;
This creates a new copy of the graphics window, closes the old window and saves it with a new name.  This is not available if SysCAD is solving or running.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;WARNING&#039;&#039;&#039;&amp;lt;br&amp;gt; &lt;br /&gt;
This action only makes a copy of the Graphics Symbols on the page but does not save/copy any project or models information, thus it CANNOT be used to save model data NOR can it be used to make a copy of the models on the graphics page.&lt;br /&gt;
&lt;br /&gt;
If user wish to make a duplicate copy of the SysCAD models, please refer to [[Copy and Paste Graphics Commands]].&lt;br /&gt;
&lt;br /&gt;
==  Save/Rename As (Trend / Control) ==&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
|Command Path || &#039;&#039;Trend&#039;&#039; or &#039;&#039;Control - Save/Rename As&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Shortcut Key || &#039;&#039;Ctrl+Shift+A&#039;&#039;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This command is only available if the active window is a [[Trend Window|Trend]]  or [[Controls Window|Control]] window.&lt;br /&gt;
&lt;br /&gt;
This creates a new copy of the Trend / Control window, closes the old window and saves it with a new name.  This is not available if SysCAD is solving or running.&lt;br /&gt;
&lt;br /&gt;
==  Save/Rename As (Tag List) ==&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
|Command Path || &#039;&#039;Tag List - Save/Rename As&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|Shortcut Key || &#039;&#039;Ctrl+Shift+A&#039;&#039;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This command is only available if the active window is a [[TagList Window|Tag List]] window.&lt;br /&gt;
&lt;br /&gt;
This creates a new copy of the Tag List window, closes the old window and saves it with a new name.  This is not available if SysCAD is solving or running.&lt;br /&gt;
&lt;br /&gt;
== Changes Detected - Save Project ==&lt;br /&gt;
&lt;br /&gt;
When a project solve command is executed, if you have not saved the project or have made changes that will impact on the project solution, you will be given the following options:&lt;br /&gt;
 &lt;br /&gt;
[[Image:ChangeDetected.png]]&lt;br /&gt;
&lt;br /&gt;
* [[Image:ChangeDetected1.png]] Changes are saved in the current project, then user can proceed with project solve by pressing solve again.  (Recommended action)&lt;br /&gt;
* [[Image:ChangeDetected2.png]] Changes are saved in a new project, using current project name + version number, then user can proceed with project solve by pressing solve again. &lt;br /&gt;
* [[Image:ChangeDetected3.png]] Ignores the save change warning once, and proceeds with project solve.  If the project is solved again, the warning will be given again.&lt;br /&gt;
* [[Image:ChangeDetected4.png]] Clears the current save change warning, and proceeds with project solve.  If the project is solved again as is, the Changes Detected - Save Project message will not pop up again.  However, if user makes another change, a new warning will be given.&lt;br /&gt;
&lt;br /&gt;
NOTE: This option is enabled if the &amp;quot;Prompt to save before solve if models added/removed&amp;quot; option is ticked in the [[General Options General|General Options - Generals Tab]].&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81875</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81875"/>
		<updated>2025-04-06T21:46:06Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Formatting Keywords */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 2| Special Functions&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|This Special Function is available for use within class functions and subroutines. ClassName returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|This Special Function is available for use within class functions and subroutines. ClassTag returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81874</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81874"/>
		<updated>2025-04-06T21:45:11Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Special Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 2| Special Functions&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|This Special Function is available for use within class functions and subroutines. ClassName returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|This Special Function is available for use within class functions and subroutines. ClassTag returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81873</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81873"/>
		<updated>2025-04-06T21:44:46Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Summary Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 2| Special Functions&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|This Special Function is available for use within class functions and subroutines. ClassName returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|This Special Function is available for use within class functions and subroutines. ClassTag returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81872</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81872"/>
		<updated>2025-04-06T21:39:17Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Syntax for Subs and Functions in a Class */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81868</id>
		<title>Class - Macros</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81868"/>
		<updated>2025-04-04T02:28:47Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Macro Functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=4}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Class Macros=&lt;br /&gt;
== Macro Parameters ==&lt;br /&gt;
=== Classes Parameter ===&lt;br /&gt;
All of the class macros include a &#039;&#039;Classes&#039;&#039; parameter which is used to define the list of class instances that need to be looped through. There are a number of different ways of defining the list of class instances to be used. If the list of classes includes any class instances marked as excluded using ExcludeClass, this are ignored and excluded from the list of class instances used in the macros.&lt;br /&gt;
&lt;br /&gt;
The different methods for defining &#039;&#039;Classes&#039;&#039; to be used in macros are:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Classes!! Description !! Example&lt;br /&gt;
|-&lt;br /&gt;
|ClassType&lt;br /&gt;
|A named [[#Syntax_for_Class_Definition|Class Type Definition]].&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of the specified class definition.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassList&lt;br /&gt;
|A previously defined [[#ClassList|ClassList]] name.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be from the defined ClassList used.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TanksList, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassInstance1,…}&lt;br /&gt;
|A comma separated list of class instances, that may include indexed classes in class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be as specified in the {} list.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({T1,T2,T3}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({FeedTank,T[5],T[6],T003}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassType1,…}&lt;br /&gt;
|A comma separated list of class type definitions.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of all the specified class definitions.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({TankClass,CSTR_Class}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassArray&lt;br /&gt;
|A class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all the classes in the [[#Syntax_for_Declaring_Class_Instances|Class Array]].&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(T, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== OperationMethod Parameter ===&lt;br /&gt;
Many of the class macros include a &#039;&#039;OperationMethod&#039;&#039; parameter which is used to define the operator method to be applied to the results of the functions or values of the variables for each class instance in the list of class instances that need to be looped through. The [[Operators]] allowed are: &#039;&#039;&#039;+ - * or and bor band bxor&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For example to sum all the values of a class variable use the &amp;quot;+&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Sum = ForEach(+, TankClass, flow).&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
For example to test a bit flag in all classes use the &amp;quot;or&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AnyTanksFull = ForEach(or, TankClass, IsFull()).&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Macros==&lt;br /&gt;
When working with multiple class instances, a number of Macros are available which will perform repetitive functions on each class instance. At load time, a macro is converted into a sequence of normal code. This saves the user from writing out loops or multiple lines of code. It also makes it very easy to add and remove class instances without having to remember to adjust code using the class instances. Macros can work with a predefined ClassList or the classes list can be provided as a parameter for the macro. Class instances can be blocked from use in macros using ExcludeClass.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! RowWidth = 20%| Macro &lt;br /&gt;
! RowWidth = 20%| Macro Syntax&lt;br /&gt;
! RowWidth = 60%| Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| ForEachSub&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(classes, SubName(..))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &amp;lt;br&amp;gt;&lt;br /&gt;
Examples:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(TankClass, Exec())&lt;br /&gt;
ClassList MainTanks {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachSub(MainTanks, UpdateResults(AmbientT))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ForEachFn&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(classes, SubName(..))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachFn(Total, +, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: Total = T1.CalcArea() + T2.CalcArea() + T3.CalcArea()&lt;br /&gt;
|-&lt;br /&gt;
| ForEachVar&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(ResultVariable, OperationMethod, Classes, ClassVariable)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and storing the result in the specified variable. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(TotalVol, +, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: TotalVol = T1.Volume + T2.Volume + T3.Volume&lt;br /&gt;
|-&lt;br /&gt;
| ForEachVarSet&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet(Classes, Variable, Expression)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachVarSet&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and set the value of a numeric variable (string variables not supported) within the class to be equal to the specified value (or result of an expression). &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet({T1,T2,T3}, Height, 17)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to T1.Height = 17  T2.Height = 17  T3.Height = 17&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Macro Functions ==&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Macro Function&amp;quot; can be used in expressions similar to a function, unlike a &amp;quot;Macro&amp;quot; which can only be used like a Sub.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! RowWidth = 20%|Macro !! RowWidth = 20%|Macro Syntax !! RowWidth = 60%|Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| ForEachFnCalc&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachFnCalc(OperationMethod, Classes, FunctName(...))&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| The function macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and return the result. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Total = ForEachFnCalc(+, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ForEachVarCalc&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarCalc(OperationMethod, Classes, ClassVariable)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| The function macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and return the result. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TotalVol = ForEachVarCalc(+, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ForEach &lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEach(OperationMethod, Classes, FunctName(...)/ClassVariable)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| This function macro is the same as ForEachFnCalc or ForEachVarCalc where at load time it auto detects last parameter type and is then equivalent to ForEachFnCalc or ForEachVarCalc.&lt;br /&gt;
|-&lt;br /&gt;
| ClassCount&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassCount(Classes)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
|The function macro &#039;&#039;ClassCount&#039;&#039; returns the number of class instances in the list of classes. &amp;lt;br&amp;gt;&lt;br /&gt;
Examples: &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Count = ClassCount({TankClass})&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AveArea = ForEach(+, {T1,T2,T3}, CalcArea()) / ClassCount({T1,T2,T3})&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Other Functions and Keywords ==&lt;br /&gt;
Other functions and keywords are available when using the Class in the main PGM file. These are described in the [[#How to use the Class (Class Instances)|How to use the Class]] section.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Functions&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ForEachClass&#039;&#039;&#039; Macro Function: used to call subroutines for all instances of the class.  See [[#ForEachClass_Function|ForEachClass Function]] for more details.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEachClass.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Keywords&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ClassGrid&#039;&#039;&#039;: used to display class instances in a table layout. {{Available139|32360}}&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039;: used to define a list of class instances, the list name can then be used when in other functions such as ForEachClass and ClassGrid. {{Available139|32394}}&lt;br /&gt;
&lt;br /&gt;
== ForEachClass Function ==&lt;br /&gt;
The macro function &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is the original Macro implemented and only option available before {{Available139|32530|n|n}}. The equivalent functionality is available as &#039;&#039;&#039;ForEachSub&#039;&#039;&#039;. Original documentation: &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; provides an efficient method to loop through all instances of a class and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
ForEachClass can be used in a number of ways:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Function Syntax !! Description and Example&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassName,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through ALL instances of the defined Class (class type). &lt;br /&gt;
* All instances include those in global scope class arrays and standalone instances. &lt;br /&gt;
* In the example above, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot; will be called.  (Note, this does not include TankClass instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassNameList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({TankClass,ThickenerClass,WasherClass}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* {{Available139|31388}}&lt;br /&gt;
* Similar to above, but used to loop through ALL instances of all the defined classes in the list. &lt;br /&gt;
* In this example, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot;, &amp;quot;ThickenerClass&amp;quot; and &amp;quot;WasherClass&amp;quot; will be called.  (Note, this does not include class instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassInstanceList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank},UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;. &lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
ClassList ABC {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachClass(ABC,UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*Example 1 above is {{Available139|31388|y}}, example 2 is {{Available139|32394|y}}.&lt;br /&gt;
*Used to loop through the named instances in the specified class instances. &lt;br /&gt;
*In the above example, the function UpdateResults() will be called by Class instance &amp;quot;T1&amp;quot;, &amp;quot;T5&amp;quot;, &amp;quot;FeedTank&amp;quot;, &amp;quot;TankLine.MidTank&amp;quot; and &amp;quot;TankLine.EndTank&amp;quot; only.&lt;br /&gt;
*The ClassInstanceList can be defined using the &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; keyword, available for Build 139.32394 and later.  See [[#Examples Using ClassList|Examples - using ClassList]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassArray,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(Tanks, Init())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through all instances in the specified Array of classes. &lt;br /&gt;
* In the above example, the function Init() will be called by the class instance array &amp;quot;Tanks&amp;quot;.  (Equivalent to calling, Tank[0].init(), Tank[1].init(), etc.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Sub can have any number of parameters, however string parameters are not supported. Where multiple class names (class types) are used, they must all have the same sub with the same parameters. Available for Build 139.31388 and later. Some examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachClass({T1,T5}, SetCalcOptions(true))&lt;br /&gt;
ForEachClass({T2,T3,T4}, SetCalcOptions(false))&lt;br /&gt;
ForEachClass(TankClass, UpdateResults(EnvironmentTemperature))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
*The Class instances or Array must be in the &#039;&#039;&#039;global scope&#039;&#039;&#039; and declared before &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is called.&lt;br /&gt;
*ForEachClass is not a true function, it is a convenient &#039;&#039;&#039;Macro&#039;&#039;&#039; that generates a sequence of code at PGM load time. This is why the location of ForEachClass is important relative to declaration of class instances (because it only uses the classes already declared when encountering ForEachClass during load).&lt;br /&gt;
*Use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; to block classes from being used with the ForEachClass macro function. For example for an Array of classes use &amp;quot;ExcludeClass Tanks[0]&amp;quot; alongside &amp;quot;ExcludeWatch Tank[0]&amp;quot; to skip the first class instance in the array with any use of ForEachClass. {{Available139|31388}}&lt;br /&gt;
*A class instance within a class is excluded.&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81867</id>
		<title>Class - Using a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81867"/>
		<updated>2025-04-04T02:12:45Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Variable Display Options */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=3}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Using Class Instances=&lt;br /&gt;
Class control is used in scenarios where logic is repeated more than once in the same iteration. What makes class so useful is its application to instances. One a class is declared, instances must be defined. &lt;br /&gt;
This section will detail how to define instances and display them in the general controller. &lt;br /&gt;
&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances.&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
==Class Variable Display Options==&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Width = 20%|Function &lt;br /&gt;
! Width = 20%|Function Syntax&lt;br /&gt;
! Width = 60%|Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| Exclude Watch&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
| To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Class Comment&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 3| General Formatting Words&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| (Recommended) Keyword to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display one class instance per tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsTextLabelLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
|-&lt;br /&gt;
|RowSpan = 5|Class Grid Display Formatting Keywords&lt;br /&gt;
| colspan = 2|{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]]. &amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Examples of Grid Dsiplay Options ===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Sharing Classes between Projects ==&lt;br /&gt;
&lt;br /&gt;
The recommended method of setting up a class that will be used in a number of pgms, or projects is as follows:&lt;br /&gt;
# The &#039;&#039;&#039;CLASS&#039;&#039;&#039; definition is defined in a separate file; for example: &#039;&#039;&#039;General_Classes_and_functions.pgm&#039;&#039;&#039;&lt;br /&gt;
#*NOTE that this file must NOT contain the $ sign or EndFile token at the end of the file.&lt;br /&gt;
# For shared use in a single project - The class definition file can be stored in the project\controls folder, then inserted into other PGM files using include file syntax &#039;&#039;&#039;&amp;gt;&amp;gt;filename&#039;&#039;&#039;.&lt;br /&gt;
#*If the class definition file is stored in the same folder as the PGM file, then use &#039;&#039;&#039;&amp;gt;&amp;gt;General_Classes_and_functions.pgm&#039;&#039;&#039; to insert the file as needed.  &lt;br /&gt;
# For shared use across multiple projects - The include file can be saved in a common shared folder, then inserted into other PGM files using include file syntax &#039;&#039;&#039;&amp;gt;&amp;gt;filename&#039;&#039;&#039;, the file name needs to be the relative or full path name.  &lt;br /&gt;
#*For example: &#039;&#039;&#039;&amp;gt;&amp;gt;d:\Users\SysCAD Common Files\General_Classes_and_functions.pgm&#039;&#039;&#039;  (Also See example below)&lt;br /&gt;
#*See &#039;&#039;&#039;[[PGM_Programming_and_Conventions#Include_Files|Include Files]]&#039;&#039;&#039; for more information.&lt;br /&gt;
&lt;br /&gt;
== ClassList ==&lt;br /&gt;
{{Available139|32530}} The keyword &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; can be added to define a list or collection of class instances. The significant advantage for coder is to define the list of classes once and reference the list in multiple ForEach macros later in the code.&lt;br /&gt;
Syntax is:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList NAME {ClassInstance1,…}&amp;lt;/syntaxhighlight&amp;gt;  &amp;lt;!--(This is the same as [[Data_Types#Integer_variables_as_Enum|enum]])--&amp;gt;&lt;br /&gt;
*The classes in the list must all be of the same class definition type. &lt;br /&gt;
*The list is a comma separated list of class that can be a specific named class instances, a named class array or an indexed class within a class array.&lt;br /&gt;
*The ClassList isn’t a real variable, it is a defined name (&amp;quot;synonym&amp;quot;) that can be reused later in the code. At PGM load time, SysCAD simply sees the list of classes wherever we use the ClassList “variable” is used. &lt;br /&gt;
*The ClassList is then used in various macros (e.g. ForEachSub, ForEachVarSet, etc.) It can also be used with &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;.  &lt;br /&gt;
*Class instances can be used (repeated) in multiple lists.&lt;br /&gt;
*The ClassList can be added when declaring the class instances or they can be defined separately afterwards.&lt;br /&gt;
*:Example of adding the ClassList when declaring the class instance: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass{List(Tanks)} T1,T2,T3,T[5]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:Example of adding the ClassList after class instances have already been defined: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList ABC {T1,T2,T3,T4,T5}&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
*See [[#Examples Using ClassList|Examples - using ClassList]].&lt;br /&gt;
&lt;br /&gt;
== ExcludeClass ==&lt;br /&gt;
&lt;br /&gt;
To block a specific class instance from being used in macros (even if the class instance is in a list), use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeClass ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeClass Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeClass is primarily used for excluding the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeClassZero} or {ecz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81866</id>
		<title>Class - Macros</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81866"/>
		<updated>2025-04-04T01:13:35Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Macros */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=4}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Class Macros=&lt;br /&gt;
== Macro Parameters ==&lt;br /&gt;
=== Classes Parameter ===&lt;br /&gt;
All of the class macros include a &#039;&#039;Classes&#039;&#039; parameter which is used to define the list of class instances that need to be looped through. There are a number of different ways of defining the list of class instances to be used. If the list of classes includes any class instances marked as excluded using ExcludeClass, this are ignored and excluded from the list of class instances used in the macros.&lt;br /&gt;
&lt;br /&gt;
The different methods for defining &#039;&#039;Classes&#039;&#039; to be used in macros are:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Classes!! Description !! Example&lt;br /&gt;
|-&lt;br /&gt;
|ClassType&lt;br /&gt;
|A named [[#Syntax_for_Class_Definition|Class Type Definition]].&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of the specified class definition.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassList&lt;br /&gt;
|A previously defined [[#ClassList|ClassList]] name.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be from the defined ClassList used.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TanksList, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassInstance1,…}&lt;br /&gt;
|A comma separated list of class instances, that may include indexed classes in class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be as specified in the {} list.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({T1,T2,T3}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({FeedTank,T[5],T[6],T003}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassType1,…}&lt;br /&gt;
|A comma separated list of class type definitions.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of all the specified class definitions.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({TankClass,CSTR_Class}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassArray&lt;br /&gt;
|A class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all the classes in the [[#Syntax_for_Declaring_Class_Instances|Class Array]].&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(T, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== OperationMethod Parameter ===&lt;br /&gt;
Many of the class macros include a &#039;&#039;OperationMethod&#039;&#039; parameter which is used to define the operator method to be applied to the results of the functions or values of the variables for each class instance in the list of class instances that need to be looped through. The [[Operators]] allowed are: &#039;&#039;&#039;+ - * or and bor band bxor&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For example to sum all the values of a class variable use the &amp;quot;+&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Sum = ForEach(+, TankClass, flow).&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
For example to test a bit flag in all classes use the &amp;quot;or&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AnyTanksFull = ForEach(or, TankClass, IsFull()).&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Macros==&lt;br /&gt;
When working with multiple class instances, a number of Macros are available which will perform repetitive functions on each class instance. At load time, a macro is converted into a sequence of normal code. This saves the user from writing out loops or multiple lines of code. It also makes it very easy to add and remove class instances without having to remember to adjust code using the class instances. Macros can work with a predefined ClassList or the classes list can be provided as a parameter for the macro. Class instances can be blocked from use in macros using ExcludeClass.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! RowWidth = 20%| Macro &lt;br /&gt;
! RowWidth = 20%| Macro Syntax&lt;br /&gt;
! RowWidth = 60%| Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| ForEachSub&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(classes, SubName(..))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &amp;lt;br&amp;gt;&lt;br /&gt;
Examples:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(TankClass, Exec())&lt;br /&gt;
ClassList MainTanks {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachSub(MainTanks, UpdateResults(AmbientT))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ForEachFn&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(classes, SubName(..))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachFn(Total, +, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: Total = T1.CalcArea() + T2.CalcArea() + T3.CalcArea()&lt;br /&gt;
|-&lt;br /&gt;
| ForEachVar&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(ResultVariable, OperationMethod, Classes, ClassVariable)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and storing the result in the specified variable. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(TotalVol, +, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: TotalVol = T1.Volume + T2.Volume + T3.Volume&lt;br /&gt;
|-&lt;br /&gt;
| ForEachVarSet&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet(Classes, Variable, Expression)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachVarSet&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and set the value of a numeric variable (string variables not supported) within the class to be equal to the specified value (or result of an expression). &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet({T1,T2,T3}, Height, 17)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to T1.Height = 17  T2.Height = 17  T3.Height = 17&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Macro Functions ==&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Macro Function&amp;quot; can be used in expressions similar to a function, unlike a &amp;quot;Macro&amp;quot; which can only be used like a Sub.&lt;br /&gt;
&lt;br /&gt;
=== ForEachFnCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and return the result. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachFnCalc(OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Total = ForEachFnCalc(+, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and return the result.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarCalc(OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TotalVol = ForEachVarCalc(+, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEach ===&lt;br /&gt;
This function macro is the same as ForEachFnCalc or ForEachVarCalc where at load time it auto detects last parameter type and is then equivalent to ForEachFnCalc or ForEachVarCalc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEach(OperationMethod, Classes, FunctName(...)/ClassVariable). &lt;br /&gt;
&lt;br /&gt;
=== ClassCount ===&lt;br /&gt;
The function macro &#039;&#039;ClassCount&#039;&#039; returns the number of class instances in the list of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ClassCount(Classes).&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Count = ClassCount({TankClass})&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AveArea = ForEach(+, {T1,T2,T3}, CalcArea()) / ClassCount({T1,T2,T3})&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Functions and Keywords ==&lt;br /&gt;
Other functions and keywords are available when using the Class in the main PGM file. These are described in the [[#How to use the Class (Class Instances)|How to use the Class]] section.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Functions&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ForEachClass&#039;&#039;&#039; Macro Function: used to call subroutines for all instances of the class.  See [[#ForEachClass_Function|ForEachClass Function]] for more details.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEachClass.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Keywords&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ClassGrid&#039;&#039;&#039;: used to display class instances in a table layout. {{Available139|32360}}&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039;: used to define a list of class instances, the list name can then be used when in other functions such as ForEachClass and ClassGrid. {{Available139|32394}}&lt;br /&gt;
&lt;br /&gt;
== ForEachClass Function ==&lt;br /&gt;
The macro function &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is the original Macro implemented and only option available before {{Available139|32530|n|n}}. The equivalent functionality is available as &#039;&#039;&#039;ForEachSub&#039;&#039;&#039;. Original documentation: &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; provides an efficient method to loop through all instances of a class and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
ForEachClass can be used in a number of ways:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Function Syntax !! Description and Example&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassName,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through ALL instances of the defined Class (class type). &lt;br /&gt;
* All instances include those in global scope class arrays and standalone instances. &lt;br /&gt;
* In the example above, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot; will be called.  (Note, this does not include TankClass instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassNameList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({TankClass,ThickenerClass,WasherClass}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* {{Available139|31388}}&lt;br /&gt;
* Similar to above, but used to loop through ALL instances of all the defined classes in the list. &lt;br /&gt;
* In this example, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot;, &amp;quot;ThickenerClass&amp;quot; and &amp;quot;WasherClass&amp;quot; will be called.  (Note, this does not include class instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassInstanceList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank},UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;. &lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
ClassList ABC {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachClass(ABC,UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*Example 1 above is {{Available139|31388|y}}, example 2 is {{Available139|32394|y}}.&lt;br /&gt;
*Used to loop through the named instances in the specified class instances. &lt;br /&gt;
*In the above example, the function UpdateResults() will be called by Class instance &amp;quot;T1&amp;quot;, &amp;quot;T5&amp;quot;, &amp;quot;FeedTank&amp;quot;, &amp;quot;TankLine.MidTank&amp;quot; and &amp;quot;TankLine.EndTank&amp;quot; only.&lt;br /&gt;
*The ClassInstanceList can be defined using the &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; keyword, available for Build 139.32394 and later.  See [[#Examples Using ClassList|Examples - using ClassList]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassArray,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(Tanks, Init())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through all instances in the specified Array of classes. &lt;br /&gt;
* In the above example, the function Init() will be called by the class instance array &amp;quot;Tanks&amp;quot;.  (Equivalent to calling, Tank[0].init(), Tank[1].init(), etc.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Sub can have any number of parameters, however string parameters are not supported. Where multiple class names (class types) are used, they must all have the same sub with the same parameters. Available for Build 139.31388 and later. Some examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachClass({T1,T5}, SetCalcOptions(true))&lt;br /&gt;
ForEachClass({T2,T3,T4}, SetCalcOptions(false))&lt;br /&gt;
ForEachClass(TankClass, UpdateResults(EnvironmentTemperature))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
*The Class instances or Array must be in the &#039;&#039;&#039;global scope&#039;&#039;&#039; and declared before &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is called.&lt;br /&gt;
*ForEachClass is not a true function, it is a convenient &#039;&#039;&#039;Macro&#039;&#039;&#039; that generates a sequence of code at PGM load time. This is why the location of ForEachClass is important relative to declaration of class instances (because it only uses the classes already declared when encountering ForEachClass during load).&lt;br /&gt;
*Use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; to block classes from being used with the ForEachClass macro function. For example for an Array of classes use &amp;quot;ExcludeClass Tanks[0]&amp;quot; alongside &amp;quot;ExcludeWatch Tank[0]&amp;quot; to skip the first class instance in the array with any use of ForEachClass. {{Available139|31388}}&lt;br /&gt;
*A class instance within a class is excluded.&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81865</id>
		<title>Class - Macros</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81865"/>
		<updated>2025-04-04T01:11:47Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Macros */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=4}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Class Macros=&lt;br /&gt;
== Macro Parameters ==&lt;br /&gt;
=== Classes Parameter ===&lt;br /&gt;
All of the class macros include a &#039;&#039;Classes&#039;&#039; parameter which is used to define the list of class instances that need to be looped through. There are a number of different ways of defining the list of class instances to be used. If the list of classes includes any class instances marked as excluded using ExcludeClass, this are ignored and excluded from the list of class instances used in the macros.&lt;br /&gt;
&lt;br /&gt;
The different methods for defining &#039;&#039;Classes&#039;&#039; to be used in macros are:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Classes!! Description !! Example&lt;br /&gt;
|-&lt;br /&gt;
|ClassType&lt;br /&gt;
|A named [[#Syntax_for_Class_Definition|Class Type Definition]].&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of the specified class definition.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassList&lt;br /&gt;
|A previously defined [[#ClassList|ClassList]] name.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be from the defined ClassList used.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TanksList, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassInstance1,…}&lt;br /&gt;
|A comma separated list of class instances, that may include indexed classes in class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be as specified in the {} list.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({T1,T2,T3}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({FeedTank,T[5],T[6],T003}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassType1,…}&lt;br /&gt;
|A comma separated list of class type definitions.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of all the specified class definitions.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({TankClass,CSTR_Class}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassArray&lt;br /&gt;
|A class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all the classes in the [[#Syntax_for_Declaring_Class_Instances|Class Array]].&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(T, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== OperationMethod Parameter ===&lt;br /&gt;
Many of the class macros include a &#039;&#039;OperationMethod&#039;&#039; parameter which is used to define the operator method to be applied to the results of the functions or values of the variables for each class instance in the list of class instances that need to be looped through. The [[Operators]] allowed are: &#039;&#039;&#039;+ - * or and bor band bxor&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For example to sum all the values of a class variable use the &amp;quot;+&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Sum = ForEach(+, TankClass, flow).&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
For example to test a bit flag in all classes use the &amp;quot;or&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AnyTanksFull = ForEach(or, TankClass, IsFull()).&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Macros==&lt;br /&gt;
When working with multiple class instances, a number of Macros are available which will perform repetitive functions on each class instance. At load time, a macro is converted into a sequence of normal code. This saves the user from writing out loops or multiple lines of code. It also makes it very easy to add and remove class instances without having to remember to adjust code using the class instances. Macros can work with a predefined ClassList or the classes list can be provided as a parameter for the macro. Class instances can be blocked from use in macros using ExcludeClass.&lt;br /&gt;
&lt;br /&gt;
=== ForEachSub ===&lt;br /&gt;
The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachSub(classes, SubName(..))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Examples:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(TankClass, Exec())&lt;br /&gt;
ClassList MainTanks {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachSub(MainTanks, UpdateResults(AmbientT))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachFn ===&lt;br /&gt;
The macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and storing the result in the specified variable. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039;ForEachFn(ResultVariable, OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Bold text&#039;&#039;&#039;Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachFn(Total, +, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: Total = T1.CalcArea() + T2.CalcArea() + T3.CalcArea()&lt;br /&gt;
&lt;br /&gt;
=== ForEachVar ===&lt;br /&gt;
The macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and storing the result in the specified variable.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVar(ResultVariable, OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(TotalVol, +, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: TotalVol = T1.Volume + T2.Volume + T3.Volume&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarSet ===&lt;br /&gt;
The macro &#039;&#039;ForEachVarSet&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and set the value of a numeric variable (string variables not supported) within the class to be equal to the specified value (or result of an expression).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarSet(Classes, Variable, Expression)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet({T1,T2,T3}, Height, 17)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to T1.Height = 17  T2.Height = 17  T3.Height = 17&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! RowWidth = 20%| Macro &lt;br /&gt;
! RowWidth = 20%| Macro Syntax&lt;br /&gt;
! RowWidth = 60%| Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| ForEachSub&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(classes, SubName(..))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &amp;lt;br&amp;gt;&lt;br /&gt;
Examples:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(TankClass, Exec())&lt;br /&gt;
ClassList MainTanks {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachSub(MainTanks, UpdateResults(AmbientT))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ForEachFn&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(classes, SubName(..))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachFn(Total, +, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: Total = T1.CalcArea() + T2.CalcArea() + T3.CalcArea()&lt;br /&gt;
|-&lt;br /&gt;
| ForEachVar&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(ResultVariable, OperationMethod, Classes, ClassVariable)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and storing the result in the specified variable. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(TotalVol, +, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: TotalVol = T1.Volume + T2.Volume + T3.Volume&lt;br /&gt;
|-&lt;br /&gt;
| ForEachVarSet&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet(Classes, Variable, Expression)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachVarSet&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and set the value of a numeric variable (string variables not supported) within the class to be equal to the specified value (or result of an expression). &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet({T1,T2,T3}, Height, 17)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to T1.Height = 17  T2.Height = 17  T3.Height = 17&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Macro Functions ==&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Macro Function&amp;quot; can be used in expressions similar to a function, unlike a &amp;quot;Macro&amp;quot; which can only be used like a Sub.&lt;br /&gt;
&lt;br /&gt;
=== ForEachFnCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and return the result. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachFnCalc(OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Total = ForEachFnCalc(+, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and return the result.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarCalc(OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TotalVol = ForEachVarCalc(+, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEach ===&lt;br /&gt;
This function macro is the same as ForEachFnCalc or ForEachVarCalc where at load time it auto detects last parameter type and is then equivalent to ForEachFnCalc or ForEachVarCalc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEach(OperationMethod, Classes, FunctName(...)/ClassVariable). &lt;br /&gt;
&lt;br /&gt;
=== ClassCount ===&lt;br /&gt;
The function macro &#039;&#039;ClassCount&#039;&#039; returns the number of class instances in the list of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ClassCount(Classes).&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Count = ClassCount({TankClass})&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AveArea = ForEach(+, {T1,T2,T3}, CalcArea()) / ClassCount({T1,T2,T3})&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Functions and Keywords ==&lt;br /&gt;
Other functions and keywords are available when using the Class in the main PGM file. These are described in the [[#How to use the Class (Class Instances)|How to use the Class]] section.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Functions&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ForEachClass&#039;&#039;&#039; Macro Function: used to call subroutines for all instances of the class.  See [[#ForEachClass_Function|ForEachClass Function]] for more details.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEachClass.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Keywords&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ClassGrid&#039;&#039;&#039;: used to display class instances in a table layout. {{Available139|32360}}&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039;: used to define a list of class instances, the list name can then be used when in other functions such as ForEachClass and ClassGrid. {{Available139|32394}}&lt;br /&gt;
&lt;br /&gt;
== ForEachClass Function ==&lt;br /&gt;
The macro function &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is the original Macro implemented and only option available before {{Available139|32530|n|n}}. The equivalent functionality is available as &#039;&#039;&#039;ForEachSub&#039;&#039;&#039;. Original documentation: &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; provides an efficient method to loop through all instances of a class and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
ForEachClass can be used in a number of ways:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Function Syntax !! Description and Example&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassName,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through ALL instances of the defined Class (class type). &lt;br /&gt;
* All instances include those in global scope class arrays and standalone instances. &lt;br /&gt;
* In the example above, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot; will be called.  (Note, this does not include TankClass instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassNameList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({TankClass,ThickenerClass,WasherClass}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* {{Available139|31388}}&lt;br /&gt;
* Similar to above, but used to loop through ALL instances of all the defined classes in the list. &lt;br /&gt;
* In this example, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot;, &amp;quot;ThickenerClass&amp;quot; and &amp;quot;WasherClass&amp;quot; will be called.  (Note, this does not include class instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassInstanceList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank},UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;. &lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
ClassList ABC {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachClass(ABC,UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*Example 1 above is {{Available139|31388|y}}, example 2 is {{Available139|32394|y}}.&lt;br /&gt;
*Used to loop through the named instances in the specified class instances. &lt;br /&gt;
*In the above example, the function UpdateResults() will be called by Class instance &amp;quot;T1&amp;quot;, &amp;quot;T5&amp;quot;, &amp;quot;FeedTank&amp;quot;, &amp;quot;TankLine.MidTank&amp;quot; and &amp;quot;TankLine.EndTank&amp;quot; only.&lt;br /&gt;
*The ClassInstanceList can be defined using the &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; keyword, available for Build 139.32394 and later.  See [[#Examples Using ClassList|Examples - using ClassList]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassArray,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(Tanks, Init())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through all instances in the specified Array of classes. &lt;br /&gt;
* In the above example, the function Init() will be called by the class instance array &amp;quot;Tanks&amp;quot;.  (Equivalent to calling, Tank[0].init(), Tank[1].init(), etc.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Sub can have any number of parameters, however string parameters are not supported. Where multiple class names (class types) are used, they must all have the same sub with the same parameters. Available for Build 139.31388 and later. Some examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachClass({T1,T5}, SetCalcOptions(true))&lt;br /&gt;
ForEachClass({T2,T3,T4}, SetCalcOptions(false))&lt;br /&gt;
ForEachClass(TankClass, UpdateResults(EnvironmentTemperature))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
*The Class instances or Array must be in the &#039;&#039;&#039;global scope&#039;&#039;&#039; and declared before &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is called.&lt;br /&gt;
*ForEachClass is not a true function, it is a convenient &#039;&#039;&#039;Macro&#039;&#039;&#039; that generates a sequence of code at PGM load time. This is why the location of ForEachClass is important relative to declaration of class instances (because it only uses the classes already declared when encountering ForEachClass during load).&lt;br /&gt;
*Use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; to block classes from being used with the ForEachClass macro function. For example for an Array of classes use &amp;quot;ExcludeClass Tanks[0]&amp;quot; alongside &amp;quot;ExcludeWatch Tank[0]&amp;quot; to skip the first class instance in the array with any use of ForEachClass. {{Available139|31388}}&lt;br /&gt;
*A class instance within a class is excluded.&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81864</id>
		<title>Class - Macros</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81864"/>
		<updated>2025-04-04T01:07:08Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Macros */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=4}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Class Macros=&lt;br /&gt;
== Macro Parameters ==&lt;br /&gt;
=== Classes Parameter ===&lt;br /&gt;
All of the class macros include a &#039;&#039;Classes&#039;&#039; parameter which is used to define the list of class instances that need to be looped through. There are a number of different ways of defining the list of class instances to be used. If the list of classes includes any class instances marked as excluded using ExcludeClass, this are ignored and excluded from the list of class instances used in the macros.&lt;br /&gt;
&lt;br /&gt;
The different methods for defining &#039;&#039;Classes&#039;&#039; to be used in macros are:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Classes!! Description !! Example&lt;br /&gt;
|-&lt;br /&gt;
|ClassType&lt;br /&gt;
|A named [[#Syntax_for_Class_Definition|Class Type Definition]].&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of the specified class definition.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassList&lt;br /&gt;
|A previously defined [[#ClassList|ClassList]] name.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be from the defined ClassList used.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TanksList, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassInstance1,…}&lt;br /&gt;
|A comma separated list of class instances, that may include indexed classes in class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be as specified in the {} list.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({T1,T2,T3}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({FeedTank,T[5],T[6],T003}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassType1,…}&lt;br /&gt;
|A comma separated list of class type definitions.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of all the specified class definitions.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({TankClass,CSTR_Class}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassArray&lt;br /&gt;
|A class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all the classes in the [[#Syntax_for_Declaring_Class_Instances|Class Array]].&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(T, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== OperationMethod Parameter ===&lt;br /&gt;
Many of the class macros include a &#039;&#039;OperationMethod&#039;&#039; parameter which is used to define the operator method to be applied to the results of the functions or values of the variables for each class instance in the list of class instances that need to be looped through. The [[Operators]] allowed are: &#039;&#039;&#039;+ - * or and bor band bxor&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For example to sum all the values of a class variable use the &amp;quot;+&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Sum = ForEach(+, TankClass, flow).&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
For example to test a bit flag in all classes use the &amp;quot;or&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AnyTanksFull = ForEach(or, TankClass, IsFull()).&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Macros==&lt;br /&gt;
When working with multiple class instances, a number of Macros are available which will perform repetitive functions on each class instance. At load time, a macro is converted into a sequence of normal code. This saves the user from writing out loops or multiple lines of code. It also makes it very easy to add and remove class instances without having to remember to adjust code using the class instances. Macros can work with a predefined ClassList or the classes list can be provided as a parameter for the macro. Class instances can be blocked from use in macros using ExcludeClass.&lt;br /&gt;
&lt;br /&gt;
=== ForEachSub ===&lt;br /&gt;
The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachSub(classes, SubName(..))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Examples:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(TankClass, Exec())&lt;br /&gt;
ClassList MainTanks {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachSub(MainTanks, UpdateResults(AmbientT))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachFn ===&lt;br /&gt;
The macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and storing the result in the specified variable. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039;ForEachFn(ResultVariable, OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Bold text&#039;&#039;&#039;Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachFn(Total, +, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: Total = T1.CalcArea() + T2.CalcArea() + T3.CalcArea()&lt;br /&gt;
&lt;br /&gt;
=== ForEachVar ===&lt;br /&gt;
The macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and storing the result in the specified variable.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVar(ResultVariable, OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(TotalVol, +, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: TotalVol = T1.Volume + T2.Volume + T3.Volume&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarSet ===&lt;br /&gt;
The macro &#039;&#039;ForEachVarSet&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and set the value of a numeric variable (string variables not supported) within the class to be equal to the specified value (or result of an expression).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarSet(Classes, Variable, Expression)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet({T1,T2,T3}, Height, 17)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to T1.Height = 17  T2.Height = 17  T3.Height = 17&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! RowWidth = 20%| Macro &lt;br /&gt;
! RowWidth = 20%| Macro Syntax&lt;br /&gt;
! RowWidth = 60%| Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| ForEachSub&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(classes, SubName(..))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &amp;lt;br&amp;gt;&lt;br /&gt;
Examples:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(TankClass, Exec())&lt;br /&gt;
ClassList MainTanks {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachSub(MainTanks, UpdateResults(AmbientT))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ForEachFn&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(classes, SubName(..))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachFn(Total, +, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: Total = T1.CalcArea() + T2.CalcArea() + T3.CalcArea()&lt;br /&gt;
|-&lt;br /&gt;
| ForEachVar&lt;br /&gt;
| Example&lt;br /&gt;
| Example&lt;br /&gt;
|-&lt;br /&gt;
| ForEachVarSet|| Example || Example&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Macro Functions ==&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Macro Function&amp;quot; can be used in expressions similar to a function, unlike a &amp;quot;Macro&amp;quot; which can only be used like a Sub.&lt;br /&gt;
&lt;br /&gt;
=== ForEachFnCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and return the result. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachFnCalc(OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Total = ForEachFnCalc(+, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and return the result.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarCalc(OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TotalVol = ForEachVarCalc(+, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEach ===&lt;br /&gt;
This function macro is the same as ForEachFnCalc or ForEachVarCalc where at load time it auto detects last parameter type and is then equivalent to ForEachFnCalc or ForEachVarCalc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEach(OperationMethod, Classes, FunctName(...)/ClassVariable). &lt;br /&gt;
&lt;br /&gt;
=== ClassCount ===&lt;br /&gt;
The function macro &#039;&#039;ClassCount&#039;&#039; returns the number of class instances in the list of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ClassCount(Classes).&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Count = ClassCount({TankClass})&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AveArea = ForEach(+, {T1,T2,T3}, CalcArea()) / ClassCount({T1,T2,T3})&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Functions and Keywords ==&lt;br /&gt;
Other functions and keywords are available when using the Class in the main PGM file. These are described in the [[#How to use the Class (Class Instances)|How to use the Class]] section.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Functions&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ForEachClass&#039;&#039;&#039; Macro Function: used to call subroutines for all instances of the class.  See [[#ForEachClass_Function|ForEachClass Function]] for more details.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEachClass.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Keywords&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ClassGrid&#039;&#039;&#039;: used to display class instances in a table layout. {{Available139|32360}}&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039;: used to define a list of class instances, the list name can then be used when in other functions such as ForEachClass and ClassGrid. {{Available139|32394}}&lt;br /&gt;
&lt;br /&gt;
== ForEachClass Function ==&lt;br /&gt;
The macro function &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is the original Macro implemented and only option available before {{Available139|32530|n|n}}. The equivalent functionality is available as &#039;&#039;&#039;ForEachSub&#039;&#039;&#039;. Original documentation: &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; provides an efficient method to loop through all instances of a class and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
ForEachClass can be used in a number of ways:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Function Syntax !! Description and Example&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassName,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through ALL instances of the defined Class (class type). &lt;br /&gt;
* All instances include those in global scope class arrays and standalone instances. &lt;br /&gt;
* In the example above, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot; will be called.  (Note, this does not include TankClass instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassNameList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({TankClass,ThickenerClass,WasherClass}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* {{Available139|31388}}&lt;br /&gt;
* Similar to above, but used to loop through ALL instances of all the defined classes in the list. &lt;br /&gt;
* In this example, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot;, &amp;quot;ThickenerClass&amp;quot; and &amp;quot;WasherClass&amp;quot; will be called.  (Note, this does not include class instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassInstanceList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank},UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;. &lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
ClassList ABC {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachClass(ABC,UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*Example 1 above is {{Available139|31388|y}}, example 2 is {{Available139|32394|y}}.&lt;br /&gt;
*Used to loop through the named instances in the specified class instances. &lt;br /&gt;
*In the above example, the function UpdateResults() will be called by Class instance &amp;quot;T1&amp;quot;, &amp;quot;T5&amp;quot;, &amp;quot;FeedTank&amp;quot;, &amp;quot;TankLine.MidTank&amp;quot; and &amp;quot;TankLine.EndTank&amp;quot; only.&lt;br /&gt;
*The ClassInstanceList can be defined using the &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; keyword, available for Build 139.32394 and later.  See [[#Examples Using ClassList|Examples - using ClassList]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassArray,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(Tanks, Init())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through all instances in the specified Array of classes. &lt;br /&gt;
* In the above example, the function Init() will be called by the class instance array &amp;quot;Tanks&amp;quot;.  (Equivalent to calling, Tank[0].init(), Tank[1].init(), etc.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Sub can have any number of parameters, however string parameters are not supported. Where multiple class names (class types) are used, they must all have the same sub with the same parameters. Available for Build 139.31388 and later. Some examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachClass({T1,T5}, SetCalcOptions(true))&lt;br /&gt;
ForEachClass({T2,T3,T4}, SetCalcOptions(false))&lt;br /&gt;
ForEachClass(TankClass, UpdateResults(EnvironmentTemperature))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
*The Class instances or Array must be in the &#039;&#039;&#039;global scope&#039;&#039;&#039; and declared before &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is called.&lt;br /&gt;
*ForEachClass is not a true function, it is a convenient &#039;&#039;&#039;Macro&#039;&#039;&#039; that generates a sequence of code at PGM load time. This is why the location of ForEachClass is important relative to declaration of class instances (because it only uses the classes already declared when encountering ForEachClass during load).&lt;br /&gt;
*Use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; to block classes from being used with the ForEachClass macro function. For example for an Array of classes use &amp;quot;ExcludeClass Tanks[0]&amp;quot; alongside &amp;quot;ExcludeWatch Tank[0]&amp;quot; to skip the first class instance in the array with any use of ForEachClass. {{Available139|31388}}&lt;br /&gt;
*A class instance within a class is excluded.&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81863</id>
		<title>Class - Macros</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81863"/>
		<updated>2025-04-04T00:56:06Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Macros */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=4}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Class Macros=&lt;br /&gt;
== Macro Parameters ==&lt;br /&gt;
=== Classes Parameter ===&lt;br /&gt;
All of the class macros include a &#039;&#039;Classes&#039;&#039; parameter which is used to define the list of class instances that need to be looped through. There are a number of different ways of defining the list of class instances to be used. If the list of classes includes any class instances marked as excluded using ExcludeClass, this are ignored and excluded from the list of class instances used in the macros.&lt;br /&gt;
&lt;br /&gt;
The different methods for defining &#039;&#039;Classes&#039;&#039; to be used in macros are:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Classes!! Description !! Example&lt;br /&gt;
|-&lt;br /&gt;
|ClassType&lt;br /&gt;
|A named [[#Syntax_for_Class_Definition|Class Type Definition]].&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of the specified class definition.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassList&lt;br /&gt;
|A previously defined [[#ClassList|ClassList]] name.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be from the defined ClassList used.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TanksList, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassInstance1,…}&lt;br /&gt;
|A comma separated list of class instances, that may include indexed classes in class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be as specified in the {} list.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({T1,T2,T3}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({FeedTank,T[5],T[6],T003}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassType1,…}&lt;br /&gt;
|A comma separated list of class type definitions.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of all the specified class definitions.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({TankClass,CSTR_Class}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassArray&lt;br /&gt;
|A class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all the classes in the [[#Syntax_for_Declaring_Class_Instances|Class Array]].&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(T, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== OperationMethod Parameter ===&lt;br /&gt;
Many of the class macros include a &#039;&#039;OperationMethod&#039;&#039; parameter which is used to define the operator method to be applied to the results of the functions or values of the variables for each class instance in the list of class instances that need to be looped through. The [[Operators]] allowed are: &#039;&#039;&#039;+ - * or and bor band bxor&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For example to sum all the values of a class variable use the &amp;quot;+&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Sum = ForEach(+, TankClass, flow).&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
For example to test a bit flag in all classes use the &amp;quot;or&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AnyTanksFull = ForEach(or, TankClass, IsFull()).&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Macros==&lt;br /&gt;
When working with multiple class instances, a number of Macros are available which will perform repetitive functions on each class instance. At load time, a macro is converted into a sequence of normal code. This saves the user from writing out loops or multiple lines of code. It also makes it very easy to add and remove class instances without having to remember to adjust code using the class instances. Macros can work with a predefined ClassList or the classes list can be provided as a parameter for the macro. Class instances can be blocked from use in macros using ExcludeClass.&lt;br /&gt;
&lt;br /&gt;
=== ForEachSub ===&lt;br /&gt;
The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachSub(classes, SubName(..))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Examples:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(TankClass, Exec())&lt;br /&gt;
ClassList MainTanks {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachSub(MainTanks, UpdateResults(AmbientT))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachFn ===&lt;br /&gt;
The macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and storing the result in the specified variable. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039;ForEachFn(ResultVariable, OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Bold text&#039;&#039;&#039;Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachFn(Total, +, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: Total = T1.CalcArea() + T2.CalcArea() + T3.CalcArea()&lt;br /&gt;
&lt;br /&gt;
=== ForEachVar ===&lt;br /&gt;
The macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and storing the result in the specified variable.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVar(ResultVariable, OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(TotalVol, +, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: TotalVol = T1.Volume + T2.Volume + T3.Volume&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarSet ===&lt;br /&gt;
The macro &#039;&#039;ForEachVarSet&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and set the value of a numeric variable (string variables not supported) within the class to be equal to the specified value (or result of an expression).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarSet(Classes, Variable, Expression)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet({T1,T2,T3}, Height, 17)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to T1.Height = 17  T2.Height = 17  T3.Height = 17&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! RowWidth = 20%| Macro &lt;br /&gt;
! RowWidth = 20%| Macro Syntax&lt;br /&gt;
! RowWidth = 60%| Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| ForEachSub&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(classes, SubName(..))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &amp;lt;br&amp;gt;&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(TankClass, Exec())&lt;br /&gt;
ClassList MainTanks {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(MainTanks, UpdateResults(AmbientT))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ForEachFn&lt;br /&gt;
| Example &lt;br /&gt;
| Example&lt;br /&gt;
|-&lt;br /&gt;
| ForEachVar|| Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| ForEachVarSet|| Example || Example&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Macro Functions ==&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Macro Function&amp;quot; can be used in expressions similar to a function, unlike a &amp;quot;Macro&amp;quot; which can only be used like a Sub.&lt;br /&gt;
&lt;br /&gt;
=== ForEachFnCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and return the result. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachFnCalc(OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Total = ForEachFnCalc(+, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and return the result.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarCalc(OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TotalVol = ForEachVarCalc(+, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEach ===&lt;br /&gt;
This function macro is the same as ForEachFnCalc or ForEachVarCalc where at load time it auto detects last parameter type and is then equivalent to ForEachFnCalc or ForEachVarCalc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEach(OperationMethod, Classes, FunctName(...)/ClassVariable). &lt;br /&gt;
&lt;br /&gt;
=== ClassCount ===&lt;br /&gt;
The function macro &#039;&#039;ClassCount&#039;&#039; returns the number of class instances in the list of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ClassCount(Classes).&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Count = ClassCount({TankClass})&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AveArea = ForEach(+, {T1,T2,T3}, CalcArea()) / ClassCount({T1,T2,T3})&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Functions and Keywords ==&lt;br /&gt;
Other functions and keywords are available when using the Class in the main PGM file. These are described in the [[#How to use the Class (Class Instances)|How to use the Class]] section.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Functions&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ForEachClass&#039;&#039;&#039; Macro Function: used to call subroutines for all instances of the class.  See [[#ForEachClass_Function|ForEachClass Function]] for more details.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEachClass.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Keywords&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ClassGrid&#039;&#039;&#039;: used to display class instances in a table layout. {{Available139|32360}}&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039;: used to define a list of class instances, the list name can then be used when in other functions such as ForEachClass and ClassGrid. {{Available139|32394}}&lt;br /&gt;
&lt;br /&gt;
== ForEachClass Function ==&lt;br /&gt;
The macro function &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is the original Macro implemented and only option available before {{Available139|32530|n|n}}. The equivalent functionality is available as &#039;&#039;&#039;ForEachSub&#039;&#039;&#039;. Original documentation: &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; provides an efficient method to loop through all instances of a class and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
ForEachClass can be used in a number of ways:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Function Syntax !! Description and Example&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassName,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through ALL instances of the defined Class (class type). &lt;br /&gt;
* All instances include those in global scope class arrays and standalone instances. &lt;br /&gt;
* In the example above, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot; will be called.  (Note, this does not include TankClass instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassNameList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({TankClass,ThickenerClass,WasherClass}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* {{Available139|31388}}&lt;br /&gt;
* Similar to above, but used to loop through ALL instances of all the defined classes in the list. &lt;br /&gt;
* In this example, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot;, &amp;quot;ThickenerClass&amp;quot; and &amp;quot;WasherClass&amp;quot; will be called.  (Note, this does not include class instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassInstanceList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank},UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;. &lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
ClassList ABC {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachClass(ABC,UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*Example 1 above is {{Available139|31388|y}}, example 2 is {{Available139|32394|y}}.&lt;br /&gt;
*Used to loop through the named instances in the specified class instances. &lt;br /&gt;
*In the above example, the function UpdateResults() will be called by Class instance &amp;quot;T1&amp;quot;, &amp;quot;T5&amp;quot;, &amp;quot;FeedTank&amp;quot;, &amp;quot;TankLine.MidTank&amp;quot; and &amp;quot;TankLine.EndTank&amp;quot; only.&lt;br /&gt;
*The ClassInstanceList can be defined using the &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; keyword, available for Build 139.32394 and later.  See [[#Examples Using ClassList|Examples - using ClassList]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassArray,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(Tanks, Init())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through all instances in the specified Array of classes. &lt;br /&gt;
* In the above example, the function Init() will be called by the class instance array &amp;quot;Tanks&amp;quot;.  (Equivalent to calling, Tank[0].init(), Tank[1].init(), etc.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Sub can have any number of parameters, however string parameters are not supported. Where multiple class names (class types) are used, they must all have the same sub with the same parameters. Available for Build 139.31388 and later. Some examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachClass({T1,T5}, SetCalcOptions(true))&lt;br /&gt;
ForEachClass({T2,T3,T4}, SetCalcOptions(false))&lt;br /&gt;
ForEachClass(TankClass, UpdateResults(EnvironmentTemperature))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
*The Class instances or Array must be in the &#039;&#039;&#039;global scope&#039;&#039;&#039; and declared before &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is called.&lt;br /&gt;
*ForEachClass is not a true function, it is a convenient &#039;&#039;&#039;Macro&#039;&#039;&#039; that generates a sequence of code at PGM load time. This is why the location of ForEachClass is important relative to declaration of class instances (because it only uses the classes already declared when encountering ForEachClass during load).&lt;br /&gt;
*Use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; to block classes from being used with the ForEachClass macro function. For example for an Array of classes use &amp;quot;ExcludeClass Tanks[0]&amp;quot; alongside &amp;quot;ExcludeWatch Tank[0]&amp;quot; to skip the first class instance in the array with any use of ForEachClass. {{Available139|31388}}&lt;br /&gt;
*A class instance within a class is excluded.&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81862</id>
		<title>Class - Using a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81862"/>
		<updated>2025-04-04T00:40:22Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Using Class Instances */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=3}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Using Class Instances=&lt;br /&gt;
Class control is used in scenarios where logic is repeated more than once in the same iteration. What makes class so useful is its application to instances. One a class is declared, instances must be defined. &lt;br /&gt;
This section will detail how to define instances and display them in the general controller. &lt;br /&gt;
&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances.&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
==Class Variable Display Options==&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Width = 20%|Function &lt;br /&gt;
! Width = 20%|Function Syntax&lt;br /&gt;
! Width = 60%|Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| Exclude Watch&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
| To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Class Comment&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 3| General Formatting Words&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| (Recommended) Keyword to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display one class instance per tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsTextLabelLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
|-&lt;br /&gt;
|RowSpan = 5|Class Grid Display Formatting Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Examples of Grid Dsiplay Options ===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Sharing Classes between Projects ==&lt;br /&gt;
&lt;br /&gt;
The recommended method of setting up a class that will be used in a number of pgms, or projects is as follows:&lt;br /&gt;
# The &#039;&#039;&#039;CLASS&#039;&#039;&#039; definition is defined in a separate file; for example: &#039;&#039;&#039;General_Classes_and_functions.pgm&#039;&#039;&#039;&lt;br /&gt;
#*NOTE that this file must NOT contain the $ sign or EndFile token at the end of the file.&lt;br /&gt;
# For shared use in a single project - The class definition file can be stored in the project\controls folder, then inserted into other PGM files using include file syntax &#039;&#039;&#039;&amp;gt;&amp;gt;filename&#039;&#039;&#039;.&lt;br /&gt;
#*If the class definition file is stored in the same folder as the PGM file, then use &#039;&#039;&#039;&amp;gt;&amp;gt;General_Classes_and_functions.pgm&#039;&#039;&#039; to insert the file as needed.  &lt;br /&gt;
# For shared use across multiple projects - The include file can be saved in a common shared folder, then inserted into other PGM files using include file syntax &#039;&#039;&#039;&amp;gt;&amp;gt;filename&#039;&#039;&#039;, the file name needs to be the relative or full path name.  &lt;br /&gt;
#*For example: &#039;&#039;&#039;&amp;gt;&amp;gt;d:\Users\SysCAD Common Files\General_Classes_and_functions.pgm&#039;&#039;&#039;  (Also See example below)&lt;br /&gt;
#*See &#039;&#039;&#039;[[PGM_Programming_and_Conventions#Include_Files|Include Files]]&#039;&#039;&#039; for more information.&lt;br /&gt;
&lt;br /&gt;
== ClassList ==&lt;br /&gt;
{{Available139|32530}} The keyword &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; can be added to define a list or collection of class instances. The significant advantage for coder is to define the list of classes once and reference the list in multiple ForEach macros later in the code.&lt;br /&gt;
Syntax is:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList NAME {ClassInstance1,…}&amp;lt;/syntaxhighlight&amp;gt;  &amp;lt;!--(This is the same as [[Data_Types#Integer_variables_as_Enum|enum]])--&amp;gt;&lt;br /&gt;
*The classes in the list must all be of the same class definition type. &lt;br /&gt;
*The list is a comma separated list of class that can be a specific named class instances, a named class array or an indexed class within a class array.&lt;br /&gt;
*The ClassList isn’t a real variable, it is a defined name (&amp;quot;synonym&amp;quot;) that can be reused later in the code. At PGM load time, SysCAD simply sees the list of classes wherever we use the ClassList “variable” is used. &lt;br /&gt;
*The ClassList is then used in various macros (e.g. ForEachSub, ForEachVarSet, etc.) It can also be used with &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;.  &lt;br /&gt;
*Class instances can be used (repeated) in multiple lists.&lt;br /&gt;
*The ClassList can be added when declaring the class instances or they can be defined separately afterwards.&lt;br /&gt;
*:Example of adding the ClassList when declaring the class instance: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass{List(Tanks)} T1,T2,T3,T[5]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:Example of adding the ClassList after class instances have already been defined: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList ABC {T1,T2,T3,T4,T5}&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
*See [[#Examples Using ClassList|Examples - using ClassList]].&lt;br /&gt;
&lt;br /&gt;
== ExcludeClass ==&lt;br /&gt;
&lt;br /&gt;
To block a specific class instance from being used in macros (even if the class instance is in a list), use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeClass ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeClass Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeClass is primarily used for excluding the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeClassZero} or {ecz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81861</id>
		<title>Class - Using a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81861"/>
		<updated>2025-04-04T00:38:32Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Using Class Instances */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=3}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Using Class Instances=&lt;br /&gt;
Class control is used in scenarios where logic is repeated more than once in the same iteration. What makes class so useful is its application to instances. One a class is declared, instances must be defined. &lt;br /&gt;
&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances.&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
==Class Variable Display Options==&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Width = 20%|Function &lt;br /&gt;
! Width = 20%|Function Syntax&lt;br /&gt;
! Width = 60%|Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| Exclude Watch&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
| To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Class Comment&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 3| General Formatting Words&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| (Recommended) Keyword to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display one class instance per tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsTextLabelLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
|-&lt;br /&gt;
|RowSpan = 5|Class Grid Display Formatting Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Examples of Grid Dsiplay Options ===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Sharing Classes between Projects ==&lt;br /&gt;
&lt;br /&gt;
The recommended method of setting up a class that will be used in a number of pgms, or projects is as follows:&lt;br /&gt;
# The &#039;&#039;&#039;CLASS&#039;&#039;&#039; definition is defined in a separate file; for example: &#039;&#039;&#039;General_Classes_and_functions.pgm&#039;&#039;&#039;&lt;br /&gt;
#*NOTE that this file must NOT contain the $ sign or EndFile token at the end of the file.&lt;br /&gt;
# For shared use in a single project - The class definition file can be stored in the project\controls folder, then inserted into other PGM files using include file syntax &#039;&#039;&#039;&amp;gt;&amp;gt;filename&#039;&#039;&#039;.&lt;br /&gt;
#*If the class definition file is stored in the same folder as the PGM file, then use &#039;&#039;&#039;&amp;gt;&amp;gt;General_Classes_and_functions.pgm&#039;&#039;&#039; to insert the file as needed.  &lt;br /&gt;
# For shared use across multiple projects - The include file can be saved in a common shared folder, then inserted into other PGM files using include file syntax &#039;&#039;&#039;&amp;gt;&amp;gt;filename&#039;&#039;&#039;, the file name needs to be the relative or full path name.  &lt;br /&gt;
#*For example: &#039;&#039;&#039;&amp;gt;&amp;gt;d:\Users\SysCAD Common Files\General_Classes_and_functions.pgm&#039;&#039;&#039;  (Also See example below)&lt;br /&gt;
#*See &#039;&#039;&#039;[[PGM_Programming_and_Conventions#Include_Files|Include Files]]&#039;&#039;&#039; for more information.&lt;br /&gt;
&lt;br /&gt;
== ClassList ==&lt;br /&gt;
{{Available139|32530}} The keyword &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; can be added to define a list or collection of class instances. The significant advantage for coder is to define the list of classes once and reference the list in multiple ForEach macros later in the code.&lt;br /&gt;
Syntax is:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList NAME {ClassInstance1,…}&amp;lt;/syntaxhighlight&amp;gt;  &amp;lt;!--(This is the same as [[Data_Types#Integer_variables_as_Enum|enum]])--&amp;gt;&lt;br /&gt;
*The classes in the list must all be of the same class definition type. &lt;br /&gt;
*The list is a comma separated list of class that can be a specific named class instances, a named class array or an indexed class within a class array.&lt;br /&gt;
*The ClassList isn’t a real variable, it is a defined name (&amp;quot;synonym&amp;quot;) that can be reused later in the code. At PGM load time, SysCAD simply sees the list of classes wherever we use the ClassList “variable” is used. &lt;br /&gt;
*The ClassList is then used in various macros (e.g. ForEachSub, ForEachVarSet, etc.) It can also be used with &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;.  &lt;br /&gt;
*Class instances can be used (repeated) in multiple lists.&lt;br /&gt;
*The ClassList can be added when declaring the class instances or they can be defined separately afterwards.&lt;br /&gt;
*:Example of adding the ClassList when declaring the class instance: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass{List(Tanks)} T1,T2,T3,T[5]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:Example of adding the ClassList after class instances have already been defined: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList ABC {T1,T2,T3,T4,T5}&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
*See [[#Examples Using ClassList|Examples - using ClassList]].&lt;br /&gt;
&lt;br /&gt;
== ExcludeClass ==&lt;br /&gt;
&lt;br /&gt;
To block a specific class instance from being used in macros (even if the class instance is in a list), use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeClass ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeClass Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeClass is primarily used for excluding the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeClassZero} or {ecz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81858</id>
		<title>Class - Using a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81858"/>
		<updated>2025-04-04T00:18:31Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Sharing Classes between Projects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=3}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Using Class Instances=&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances.&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
==Class Variable Display Options==&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Width = 20%|Function &lt;br /&gt;
! Width = 20%|Function Syntax&lt;br /&gt;
! Width = 60%|Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| Exclude Watch&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
| To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Class Comment&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 3| General Formatting Words&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| (Recommended) Keyword to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display one class instance per tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsTextLabelLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
|-&lt;br /&gt;
|RowSpan = 5|Class Grid Display Formatting Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Examples of Grid Dsiplay Options ===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Sharing Classes between Projects ==&lt;br /&gt;
&lt;br /&gt;
The recommended method of setting up a class that will be used in a number of pgms, or projects is as follows:&lt;br /&gt;
# The &#039;&#039;&#039;CLASS&#039;&#039;&#039; definition is defined in a separate file; for example: &#039;&#039;&#039;General_Classes_and_functions.pgm&#039;&#039;&#039;&lt;br /&gt;
#*NOTE that this file must NOT contain the $ sign or EndFile token at the end of the file.&lt;br /&gt;
# For shared use in a single project - The class definition file can be stored in the project\controls folder, then inserted into other PGM files using include file syntax &#039;&#039;&#039;&amp;gt;&amp;gt;filename&#039;&#039;&#039;.&lt;br /&gt;
#*If the class definition file is stored in the same folder as the PGM file, then use &#039;&#039;&#039;&amp;gt;&amp;gt;General_Classes_and_functions.pgm&#039;&#039;&#039; to insert the file as needed.  &lt;br /&gt;
# For shared use across multiple projects - The include file can be saved in a common shared folder, then inserted into other PGM files using include file syntax &#039;&#039;&#039;&amp;gt;&amp;gt;filename&#039;&#039;&#039;, the file name needs to be the relative or full path name.  &lt;br /&gt;
#*For example: &#039;&#039;&#039;&amp;gt;&amp;gt;d:\Users\SysCAD Common Files\General_Classes_and_functions.pgm&#039;&#039;&#039;  (Also See example below)&lt;br /&gt;
#*See &#039;&#039;&#039;[[PGM_Programming_and_Conventions#Include_Files|Include Files]]&#039;&#039;&#039; for more information.&lt;br /&gt;
&lt;br /&gt;
== ClassList ==&lt;br /&gt;
{{Available139|32530}} The keyword &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; can be added to define a list or collection of class instances. The significant advantage for coder is to define the list of classes once and reference the list in multiple ForEach macros later in the code.&lt;br /&gt;
Syntax is:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList NAME {ClassInstance1,…}&amp;lt;/syntaxhighlight&amp;gt;  &amp;lt;!--(This is the same as [[Data_Types#Integer_variables_as_Enum|enum]])--&amp;gt;&lt;br /&gt;
*The classes in the list must all be of the same class definition type. &lt;br /&gt;
*The list is a comma separated list of class that can be a specific named class instances, a named class array or an indexed class within a class array.&lt;br /&gt;
*The ClassList isn’t a real variable, it is a defined name (&amp;quot;synonym&amp;quot;) that can be reused later in the code. At PGM load time, SysCAD simply sees the list of classes wherever we use the ClassList “variable” is used. &lt;br /&gt;
*The ClassList is then used in various macros (e.g. ForEachSub, ForEachVarSet, etc.) It can also be used with &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;.  &lt;br /&gt;
*Class instances can be used (repeated) in multiple lists.&lt;br /&gt;
*The ClassList can be added when declaring the class instances or they can be defined separately afterwards.&lt;br /&gt;
*:Example of adding the ClassList when declaring the class instance: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass{List(Tanks)} T1,T2,T3,T[5]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:Example of adding the ClassList after class instances have already been defined: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList ABC {T1,T2,T3,T4,T5}&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
*See [[#Examples Using ClassList|Examples - using ClassList]].&lt;br /&gt;
&lt;br /&gt;
== ExcludeClass ==&lt;br /&gt;
&lt;br /&gt;
To block a specific class instance from being used in macros (even if the class instance is in a list), use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeClass ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeClass Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeClass is primarily used for excluding the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeClassZero} or {ecz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81857</id>
		<title>Class - Using a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81857"/>
		<updated>2025-04-04T00:14:55Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Examples of Grid Dsiplay Options */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=3}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Using Class Instances=&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances.&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
==Class Variable Display Options==&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Width = 20%|Function &lt;br /&gt;
! Width = 20%|Function Syntax&lt;br /&gt;
! Width = 60%|Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| Exclude Watch&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
| To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Class Comment&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 3| General Formatting Words&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| (Recommended) Keyword to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display one class instance per tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsTextLabelLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
|-&lt;br /&gt;
|RowSpan = 5|Class Grid Display Formatting Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Examples of Grid Dsiplay Options ===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Sharing Classes between Projects ==&lt;br /&gt;
&lt;br /&gt;
The recommended method of setting up a class that will be used in a number of pgms, or projects is as follows:&lt;br /&gt;
# The &#039;&#039;&#039;CLASS&#039;&#039;&#039; definition is defined in a separate file; for example: &#039;&#039;&#039;General_Classes_and_functions.pgm&#039;&#039;&#039;&lt;br /&gt;
#*NOTE that this file must NOT contain the $ sign or EndFile token at the end of the file.&lt;br /&gt;
# For shared use in a single project - The class definition file can be stored in the project\controls folder, then inserted into other PGM files using include file syntax &#039;&#039;&#039;&amp;gt;&amp;gt;filename&#039;&#039;&#039;.&lt;br /&gt;
#*If the class definition file is stored in the same folder as the PGM file, then use &#039;&#039;&#039;&amp;gt;&amp;gt;General_Classes_and_functions.pgm&#039;&#039;&#039; to insert the file as needed.  &lt;br /&gt;
# For shared use across multiple projects - The include file can be saved in a common shared folder, then inserted into other PGM files using include file syntax &#039;&#039;&#039;&amp;gt;&amp;gt;filename&#039;&#039;&#039;, the file name needs to be the relative or full path name.  &lt;br /&gt;
#*For example: &#039;&#039;&#039;&amp;gt;&amp;gt;d:\Users\SysCAD Common Files\General_Classes_and_functions.pgm&#039;&#039;&#039;  (Also See example below)&lt;br /&gt;
#*See &#039;&#039;&#039;[[PGM_Programming_and_Conventions#Include_Files|Include Files]]&#039;&#039;&#039; for more information.&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81856</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81856"/>
		<updated>2025-04-04T00:13:51Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Syntax for Class Instance Definition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81855</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81855"/>
		<updated>2025-04-04T00:13:13Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Instance Variable Display Options */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81854</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81854"/>
		<updated>2025-04-04T00:12:13Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Variable Display Options */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81853</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81853"/>
		<updated>2025-04-04T00:11:22Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Syntax for Instance Definition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Class Variable Display Options==&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Width = 20%|Function &lt;br /&gt;
! Width = 20%|Function Syntax&lt;br /&gt;
! Width = 60%|Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| Exclude Watch&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
| To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Class Comment&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 3| General Formatting Words&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| (Recommended) Keyword to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display one class instance per tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsTextLabelLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
|-&lt;br /&gt;
|RowSpan = 5|Class Grid Display Formatting Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Examples of Grid Dsiplay Options ===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81852</id>
		<title>Class - Using a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81852"/>
		<updated>2025-04-04T00:07:59Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Syntax for Instance Definition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=3}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Using Class Instances=&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances.&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
==Class Variable Display Options==&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Width = 20%|Function &lt;br /&gt;
! Width = 20%|Function Syntax&lt;br /&gt;
! Width = 60%|Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| Exclude Watch&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
| To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Class Comment&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 3| General Formatting Words&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| (Recommended) Keyword to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display one class instance per tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsTextLabelLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
|-&lt;br /&gt;
|RowSpan = 5|Class Grid Display Formatting Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Examples of Grid Dsiplay Options ===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81851</id>
		<title>Class - Using a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Using_a_Class&amp;diff=81851"/>
		<updated>2025-04-04T00:07:08Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Using Class Instances */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=3}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Using Class Instances=&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances.&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81850</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81850"/>
		<updated>2025-04-04T00:03:56Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* ExcludeWatch */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances.&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
==Class Variable Display Options==&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Width = 20%|Function &lt;br /&gt;
! Width = 20%|Function Syntax&lt;br /&gt;
! Width = 60%|Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| Exclude Watch&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
| To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Class Comment&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 3| General Formatting Words&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| (Recommended) Keyword to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display one class instance per tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsTextLabelLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
|-&lt;br /&gt;
|RowSpan = 5|Class Grid Display Formatting Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Examples of Grid Dsiplay Options ===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81849</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81849"/>
		<updated>2025-04-04T00:02:45Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* ExcludeWatch */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances.&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
==Class Variable Display Options==&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Width = 20%|Function &lt;br /&gt;
! Width = 20%|Function Syntax&lt;br /&gt;
! Width = 60%|Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| Exclude Watch&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
| To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Class Comment&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 3| General Formatting Words&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| (Recommended) Keyword to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display one class instance per tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsTextLabelLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
|-&lt;br /&gt;
|RowSpan = 5|Class Grid Display Formatting Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
|}&lt;br /&gt;
=== Examples of Grid Dsiplay Options ===&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81848</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81848"/>
		<updated>2025-04-04T00:00:11Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Variable Display Options */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances.&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
==Class Variable Display Options==&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Width = 20%|Function &lt;br /&gt;
! Width = 20%|Function Syntax&lt;br /&gt;
! Width = 60%|Description/Notes/Examples&lt;br /&gt;
|-&lt;br /&gt;
| Exclude Watch&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt; &lt;br /&gt;
| To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Class Comment&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
| After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 3| General Formatting Words&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| (Recommended) Keyword to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display one class instance per tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt; ClassAsTextLabelLabel&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
|-&lt;br /&gt;
|RowSpan = 5|Class Grid Display Formatting Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
:Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81846</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81846"/>
		<updated>2025-04-03T22:46:42Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Syntax for Instance Definition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances.&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
==Class Variable Display Options==&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81798</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81798"/>
		<updated>2025-04-01T23:33:23Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Syntax for Instance Definition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances.&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81797</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81797"/>
		<updated>2025-04-01T23:30:41Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Syntax for Instance Definition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81796</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81796"/>
		<updated>2025-04-01T23:17:40Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Syntax for Instance Definition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
|10&lt;br /&gt;
|10.5&lt;br /&gt;
|-&lt;br /&gt;
|11&lt;br /&gt;
|12&lt;br /&gt;
|13&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81795</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81795"/>
		<updated>2025-04-01T23:16:51Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Syntax for Instance Definition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Rowspan = 5| Syntax for Interactive with Class Instances&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;VariableTag.UnitTag = &amp;quot;InstanceTag&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Value =&amp;quot;ClassInstance.ClassVariable &amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ClassInstance.Function()&lt;br /&gt;
ClassInstance.Subroutine()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
|10&lt;br /&gt;
|10.5&lt;br /&gt;
|-&lt;br /&gt;
|11&lt;br /&gt;
|12&lt;br /&gt;
|13&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81794</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81794"/>
		<updated>2025-04-01T23:00:43Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Summary Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Syntax for Instance Definition==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Class instances can be declared individually (in the same way normal data variables are declared) or as an array of class instances.&lt;br /&gt;
Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81793</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81793"/>
		<updated>2025-04-01T22:57:15Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Summary Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Caption text&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Instance Definition&lt;br /&gt;
| Individually: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance_1, Instance_2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassName Instance[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Class instances can be declared individually (in the same way normal data variables are declared) or as an array of class instances.&lt;br /&gt;
Examples:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;CSTR_Class Tank_1, Tank_2&lt;br /&gt;
CSTR_Class Tank[3] &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81792</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81792"/>
		<updated>2025-04-01T22:53:36Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Summary Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Caption text&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 5| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use ths keyword to hide the display of all TextLabels shown a text between rows in the grid.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. &lt;br /&gt;
&lt;br /&gt;
Example:  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81791</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81791"/>
		<updated>2025-04-01T22:49:22Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Summary Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Caption text&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| RowSpan = 3| Specal Functions - Grid Display Keywords&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the width of each column displayed in a grid class.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Use this keyword to hide the display of class instance comments that are normally displayed in the first row of the grid.&lt;br /&gt;
|-&lt;br /&gt;
| 10|| 11|| 12&lt;br /&gt;
|-&lt;br /&gt;
| 13|| 14|| 15&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81790</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81790"/>
		<updated>2025-04-01T22:43:15Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Syntax Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Caption text&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81789</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81789"/>
		<updated>2025-04-01T22:42:32Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Summary Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Syntax Summary==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=10%|Function !! width=20%|Function Syntax !! width=35%|Data Type !! width=45%|Description / Examples / Notes&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class className&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;className&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
This is the logic used to declare and name the class. All of the class logic will be contained by these statements.&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=2|Class Variable Declaration&lt;br /&gt;
|&lt;br /&gt;
|rowspan=2|&lt;br /&gt;
*Variables can be declared within a class.&lt;br /&gt;
*Each declared variable within a class will exist for each instance of that class.&lt;br /&gt;
*Their scope is limited to that class.&lt;br /&gt;
|rowspan=2|&lt;br /&gt;
Normal variable declarition rules apply to these variables:&lt;br /&gt;
*The user can define units&lt;br /&gt;
*Append * or @ to make th variable visable in the access window and writable (*) or read-only (@)&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
variable = GetDynTag(&amp;quot;full tag&amp;quot;)&lt;br /&gt;
variable = GetDynTag(string)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Getting Tag from SysCAD &amp;lt;br&amp;gt; &#039;&#039;&#039;Alternative Syntax&#039;&#039;&#039;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
variable = GetDynStrTag(string)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
*&#039;&#039;&#039;variable:&#039;&#039;&#039; This should be a [[PGM Programming and Conventions#Data Types| STR]] variable type&lt;br /&gt;
*&#039;&#039;&#039;string&#039;&#039;&#039;: is a variable of type [[PGM Programming and Conventions#Data Types| STR]] that refers to a tag.  A conversion may also be specified within the &#039;&#039;&#039;string&#039;&#039;&#039;.  See [[PGM Programming and Conventions#Tags |Tags]] for the correct tag syntax.&lt;br /&gt;
|&lt;br /&gt;
*returns the Tag name of the parameter, referred to by the tag contained in &#039;&#039;&#039;string&#039;&#039;&#039;.&lt;br /&gt;
*See [[#Examples|Example 2]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Caption text&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 20%| Function Syntax !! width = 60%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class ClassName&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Syntax for Subs and Functions&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Sub SubroutineName()&lt;br /&gt;
Function FunctionName()&lt;br /&gt;
StrFunction StrFunctionName() &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
* Initialise subroutine&lt;br /&gt;
* Calculation subroutine(s)&lt;br /&gt;
* Execute subroutine&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| Special Functions - General Keywords&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsGroup &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsPageLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| Available from Build 139.31388. If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page.&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt; ClassAsTextLabel &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81788</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81788"/>
		<updated>2025-04-01T22:33:38Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Summary Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Syntax Summary==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=10%|Function !! width=20%|Function Syntax !! width=35%|Data Type !! width=45%|Description / Examples / Notes&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class className&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;className&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
This is the logic used to declare and name the class. All of the class logic will be contained by these statements.&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=2|Class Variable Declaration&lt;br /&gt;
|&lt;br /&gt;
|rowspan=2|&lt;br /&gt;
*Variables can be declared within a class.&lt;br /&gt;
*Each declared variable within a class will exist for each instance of that class.&lt;br /&gt;
*Their scope is limited to that class.&lt;br /&gt;
|rowspan=2|&lt;br /&gt;
Normal variable declarition rules apply to these variables:&lt;br /&gt;
*The user can define units&lt;br /&gt;
*Append * or @ to make th variable visable in the access window and writable (*) or read-only (@)&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
variable = GetDynTag(&amp;quot;full tag&amp;quot;)&lt;br /&gt;
variable = GetDynTag(string)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Getting Tag from SysCAD &amp;lt;br&amp;gt; &#039;&#039;&#039;Alternative Syntax&#039;&#039;&#039;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
variable = GetDynStrTag(string)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
*&#039;&#039;&#039;variable:&#039;&#039;&#039; This should be a [[PGM Programming and Conventions#Data Types| STR]] variable type&lt;br /&gt;
*&#039;&#039;&#039;string&#039;&#039;&#039;: is a variable of type [[PGM Programming and Conventions#Data Types| STR]] that refers to a tag.  A conversion may also be specified within the &#039;&#039;&#039;string&#039;&#039;&#039;.  See [[PGM Programming and Conventions#Tags |Tags]] for the correct tag syntax.&lt;br /&gt;
|&lt;br /&gt;
*returns the Tag name of the parameter, referred to by the tag contained in &#039;&#039;&#039;string&#039;&#039;&#039;.&lt;br /&gt;
*See [[#Examples|Example 2]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Caption text&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 30%| Function Syntax !! width = 45%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class className&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| *&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;className&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| Class Variable Declaration&lt;br /&gt;
| &lt;br /&gt;
| Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 7|| 8 || 9&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| 10|| 11||12&lt;br /&gt;
|-&lt;br /&gt;
| 13|| 14|&lt;br /&gt;
|-&lt;br /&gt;
| 16|| 17|&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81787</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81787"/>
		<updated>2025-04-01T22:29:25Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Summary Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Syntax Summary==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=10%|Function !! width=20%|Function Syntax !! width=35%|Data Type !! width=45%|Description / Examples / Notes&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class className&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;className&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
This is the logic used to declare and name the class. All of the class logic will be contained by these statements.&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=2|Class Variable Declaration&lt;br /&gt;
|&lt;br /&gt;
|rowspan=2|&lt;br /&gt;
*Variables can be declared within a class.&lt;br /&gt;
*Each declared variable within a class will exist for each instance of that class.&lt;br /&gt;
*Their scope is limited to that class.&lt;br /&gt;
|rowspan=2|&lt;br /&gt;
Normal variable declarition rules apply to these variables:&lt;br /&gt;
*The user can define units&lt;br /&gt;
*Append * or @ to make th variable visable in the access window and writable (*) or read-only (@)&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
variable = GetDynTag(&amp;quot;full tag&amp;quot;)&lt;br /&gt;
variable = GetDynTag(string)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Getting Tag from SysCAD &amp;lt;br&amp;gt; &#039;&#039;&#039;Alternative Syntax&#039;&#039;&#039;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
variable = GetDynStrTag(string)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
*&#039;&#039;&#039;variable:&#039;&#039;&#039; This should be a [[PGM Programming and Conventions#Data Types| STR]] variable type&lt;br /&gt;
*&#039;&#039;&#039;string&#039;&#039;&#039;: is a variable of type [[PGM Programming and Conventions#Data Types| STR]] that refers to a tag.  A conversion may also be specified within the &#039;&#039;&#039;string&#039;&#039;&#039;.  See [[PGM Programming and Conventions#Tags |Tags]] for the correct tag syntax.&lt;br /&gt;
|&lt;br /&gt;
*returns the Tag name of the parameter, referred to by the tag contained in &#039;&#039;&#039;string&#039;&#039;&#039;.&lt;br /&gt;
*See [[#Examples|Example 2]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Caption text&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 40%| Function Syntax !! width = 40%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class|| 2|| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4|| 5|| 6&lt;br /&gt;
|-&lt;br /&gt;
| 7|| 8 || 9&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| 10|| 11||12&lt;br /&gt;
|-&lt;br /&gt;
| 13|| 14|&lt;br /&gt;
|-&lt;br /&gt;
| 16|| 17|&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81786</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81786"/>
		<updated>2025-04-01T22:27:44Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Summary Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Syntax Summary==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=10%|Function !! width=20%|Function Syntax !! width=35%|Data Type !! width=45%|Description / Examples / Notes&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class className&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;className&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
This is the logic used to declare and name the class. All of the class logic will be contained by these statements.&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=2|Class Variable Declaration&lt;br /&gt;
|&lt;br /&gt;
|rowspan=2|&lt;br /&gt;
*Variables can be declared within a class.&lt;br /&gt;
*Each declared variable within a class will exist for each instance of that class.&lt;br /&gt;
*Their scope is limited to that class.&lt;br /&gt;
|rowspan=2|&lt;br /&gt;
Normal variable declarition rules apply to these variables:&lt;br /&gt;
*The user can define units&lt;br /&gt;
*Append * or @ to make th variable visable in the access window and writable (*) or read-only (@)&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
variable = GetDynTag(&amp;quot;full tag&amp;quot;)&lt;br /&gt;
variable = GetDynTag(string)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Getting Tag from SysCAD &amp;lt;br&amp;gt; &#039;&#039;&#039;Alternative Syntax&#039;&#039;&#039;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
variable = GetDynStrTag(string)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
*&#039;&#039;&#039;variable:&#039;&#039;&#039; This should be a [[PGM Programming and Conventions#Data Types| STR]] variable type&lt;br /&gt;
*&#039;&#039;&#039;string&#039;&#039;&#039;: is a variable of type [[PGM Programming and Conventions#Data Types| STR]] that refers to a tag.  A conversion may also be specified within the &#039;&#039;&#039;string&#039;&#039;&#039;.  See [[PGM Programming and Conventions#Tags |Tags]] for the correct tag syntax.&lt;br /&gt;
|&lt;br /&gt;
*returns the Tag name of the parameter, referred to by the tag contained in &#039;&#039;&#039;string&#039;&#039;&#039;.&lt;br /&gt;
*See [[#Examples|Example 2]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Caption text&lt;br /&gt;
|-&lt;br /&gt;
! width = 20%|Function!! width = 40%| Function Syntax !! width = 40%| Description/Notes/Example&lt;br /&gt;
|-&lt;br /&gt;
| 1|| 2|| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4|| 5|| 6&lt;br /&gt;
|-&lt;br /&gt;
| 7|| 8 || 9&lt;br /&gt;
|-&lt;br /&gt;
|rowspan = 3| 10|| 11||12&lt;br /&gt;
|-&lt;br /&gt;
| 13|| 14||15|&lt;br /&gt;
|-&lt;br /&gt;
| 16|| 17|| 18&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|-&lt;br /&gt;
| Example || Example || Example&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81785</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81785"/>
		<updated>2025-04-01T07:22:21Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Syntax Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Syntax Summary==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=10%|Function !! width=20%|Function Syntax !! width=35%|Data Type !! width=45%|Description / Examples / Notes&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class className&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;className&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
This is the logic used to declare and name the class. All of the class logic will be contained by these statements.&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=2|Class Variable Declaration&lt;br /&gt;
|&lt;br /&gt;
|rowspan=2|&lt;br /&gt;
*Variables can be declared within a class.&lt;br /&gt;
*Each declared variable within a class will exist for each instance of that class.&lt;br /&gt;
*Their scope is limited to that class.&lt;br /&gt;
|rowspan=2|&lt;br /&gt;
Normal variable declarition rules apply to these variables:&lt;br /&gt;
*The user can define units&lt;br /&gt;
*Append * or @ to make th variable visable in the access window and writable (*) or read-only (@)&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
variable = GetDynTag(&amp;quot;full tag&amp;quot;)&lt;br /&gt;
variable = GetDynTag(string)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Getting Tag from SysCAD &amp;lt;br&amp;gt; &#039;&#039;&#039;Alternative Syntax&#039;&#039;&#039;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
variable = GetDynStrTag(string)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
*&#039;&#039;&#039;variable:&#039;&#039;&#039; This should be a [[PGM Programming and Conventions#Data Types| STR]] variable type&lt;br /&gt;
*&#039;&#039;&#039;string&#039;&#039;&#039;: is a variable of type [[PGM Programming and Conventions#Data Types| STR]] that refers to a tag.  A conversion may also be specified within the &#039;&#039;&#039;string&#039;&#039;&#039;.  See [[PGM Programming and Conventions#Tags |Tags]] for the correct tag syntax.&lt;br /&gt;
|&lt;br /&gt;
*returns the Tag name of the parameter, referred to by the tag contained in &#039;&#039;&#039;string&#039;&#039;&#039;.&lt;br /&gt;
*See [[#Examples|Example 2]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Summary Table==&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81784</id>
		<title>Class - Macros</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81784"/>
		<updated>2025-04-01T07:14:56Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Other Functions and Keywords */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=4}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Class Macros=&lt;br /&gt;
== Macro Parameters ==&lt;br /&gt;
=== Classes Parameter ===&lt;br /&gt;
All of the class macros include a &#039;&#039;Classes&#039;&#039; parameter which is used to define the list of class instances that need to be looped through. There are a number of different ways of defining the list of class instances to be used. If the list of classes includes any class instances marked as excluded using ExcludeClass, this are ignored and excluded from the list of class instances used in the macros.&lt;br /&gt;
&lt;br /&gt;
The different methods for defining &#039;&#039;Classes&#039;&#039; to be used in macros are:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Classes!! Description !! Example&lt;br /&gt;
|-&lt;br /&gt;
|ClassType&lt;br /&gt;
|A named [[#Syntax_for_Class_Definition|Class Type Definition]].&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of the specified class definition.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassList&lt;br /&gt;
|A previously defined [[#ClassList|ClassList]] name.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be from the defined ClassList used.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TanksList, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassInstance1,…}&lt;br /&gt;
|A comma separated list of class instances, that may include indexed classes in class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be as specified in the {} list.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({T1,T2,T3}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({FeedTank,T[5],T[6],T003}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassType1,…}&lt;br /&gt;
|A comma separated list of class type definitions.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of all the specified class definitions.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({TankClass,CSTR_Class}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassArray&lt;br /&gt;
|A class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all the classes in the [[#Syntax_for_Declaring_Class_Instances|Class Array]].&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(T, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== OperationMethod Parameter ===&lt;br /&gt;
Many of the class macros include a &#039;&#039;OperationMethod&#039;&#039; parameter which is used to define the operator method to be applied to the results of the functions or values of the variables for each class instance in the list of class instances that need to be looped through. The [[Operators]] allowed are: &#039;&#039;&#039;+ - * or and bor band bxor&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For example to sum all the values of a class variable use the &amp;quot;+&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Sum = ForEach(+, TankClass, flow).&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
For example to test a bit flag in all classes use the &amp;quot;or&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AnyTanksFull = ForEach(or, TankClass, IsFull()).&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Macros==&lt;br /&gt;
When working with multiple class instances, a number of Macros are available which will perform repetitive functions on each class instance. At load time, a macro is converted into a sequence of normal code. This saves the user from writing out loops or multiple lines of code. It also makes it very easy to add and remove class instances without having to remember to adjust code using the class instances. Macros can work with a predefined ClassList or the classes list can be provided as a parameter for the macro. Class instances can be blocked from use in macros using ExcludeClass.&lt;br /&gt;
&lt;br /&gt;
=== ForEachSub ===&lt;br /&gt;
The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachSub(classes, SubName(..))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Examples:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(TankClass, Exec())&lt;br /&gt;
ClassList MainTanks {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachSub(MainTanks, UpdateResults(AmbientT))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachFn ===&lt;br /&gt;
The macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and storing the result in the specified variable. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039;ForEachFn(ResultVariable, OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Bold text&#039;&#039;&#039;Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachFn(Total, +, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: Total = T1.CalcArea() + T2.CalcArea() + T3.CalcArea()&lt;br /&gt;
&lt;br /&gt;
=== ForEachVar ===&lt;br /&gt;
The macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and storing the result in the specified variable.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVar(ResultVariable, OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(TotalVol, +, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: TotalVol = T1.Volume + T2.Volume + T3.Volume&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarSet ===&lt;br /&gt;
The macro &#039;&#039;ForEachVarSet&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and set the value of a numeric variable (string variables not supported) within the class to be equal to the specified value (or result of an expression).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarSet(Classes, Variable, Expression)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet({T1,T2,T3}, Height, 17)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to T1.Height = 17  T2.Height = 17  T3.Height = 17&lt;br /&gt;
&lt;br /&gt;
== Macro Functions ==&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Macro Function&amp;quot; can be used in expressions similar to a function, unlike a &amp;quot;Macro&amp;quot; which can only be used like a Sub.&lt;br /&gt;
&lt;br /&gt;
=== ForEachFnCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and return the result. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachFnCalc(OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Total = ForEachFnCalc(+, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and return the result.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarCalc(OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TotalVol = ForEachVarCalc(+, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEach ===&lt;br /&gt;
This function macro is the same as ForEachFnCalc or ForEachVarCalc where at load time it auto detects last parameter type and is then equivalent to ForEachFnCalc or ForEachVarCalc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEach(OperationMethod, Classes, FunctName(...)/ClassVariable). &lt;br /&gt;
&lt;br /&gt;
=== ClassCount ===&lt;br /&gt;
The function macro &#039;&#039;ClassCount&#039;&#039; returns the number of class instances in the list of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ClassCount(Classes).&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Count = ClassCount({TankClass})&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AveArea = ForEach(+, {T1,T2,T3}, CalcArea()) / ClassCount({T1,T2,T3})&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Functions and Keywords ==&lt;br /&gt;
Other functions and keywords are available when using the Class in the main PGM file. These are described in the [[#How to use the Class (Class Instances)|How to use the Class]] section.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Functions&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ForEachClass&#039;&#039;&#039; Macro Function: used to call subroutines for all instances of the class.  See [[#ForEachClass_Function|ForEachClass Function]] for more details.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEachClass.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Keywords&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ClassGrid&#039;&#039;&#039;: used to display class instances in a table layout. {{Available139|32360}}&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039;: used to define a list of class instances, the list name can then be used when in other functions such as ForEachClass and ClassGrid. {{Available139|32394}}&lt;br /&gt;
&lt;br /&gt;
== ForEachClass Function ==&lt;br /&gt;
The macro function &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is the original Macro implemented and only option available before {{Available139|32530|n|n}}. The equivalent functionality is available as &#039;&#039;&#039;ForEachSub&#039;&#039;&#039;. Original documentation: &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; provides an efficient method to loop through all instances of a class and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
ForEachClass can be used in a number of ways:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Function Syntax !! Description and Example&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassName,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through ALL instances of the defined Class (class type). &lt;br /&gt;
* All instances include those in global scope class arrays and standalone instances. &lt;br /&gt;
* In the example above, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot; will be called.  (Note, this does not include TankClass instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassNameList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({TankClass,ThickenerClass,WasherClass}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* {{Available139|31388}}&lt;br /&gt;
* Similar to above, but used to loop through ALL instances of all the defined classes in the list. &lt;br /&gt;
* In this example, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot;, &amp;quot;ThickenerClass&amp;quot; and &amp;quot;WasherClass&amp;quot; will be called.  (Note, this does not include class instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassInstanceList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank},UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;. &lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
ClassList ABC {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachClass(ABC,UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*Example 1 above is {{Available139|31388|y}}, example 2 is {{Available139|32394|y}}.&lt;br /&gt;
*Used to loop through the named instances in the specified class instances. &lt;br /&gt;
*In the above example, the function UpdateResults() will be called by Class instance &amp;quot;T1&amp;quot;, &amp;quot;T5&amp;quot;, &amp;quot;FeedTank&amp;quot;, &amp;quot;TankLine.MidTank&amp;quot; and &amp;quot;TankLine.EndTank&amp;quot; only.&lt;br /&gt;
*The ClassInstanceList can be defined using the &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; keyword, available for Build 139.32394 and later.  See [[#Examples Using ClassList|Examples - using ClassList]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassArray,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(Tanks, Init())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through all instances in the specified Array of classes. &lt;br /&gt;
* In the above example, the function Init() will be called by the class instance array &amp;quot;Tanks&amp;quot;.  (Equivalent to calling, Tank[0].init(), Tank[1].init(), etc.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Sub can have any number of parameters, however string parameters are not supported. Where multiple class names (class types) are used, they must all have the same sub with the same parameters. Available for Build 139.31388 and later. Some examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachClass({T1,T5}, SetCalcOptions(true))&lt;br /&gt;
ForEachClass({T2,T3,T4}, SetCalcOptions(false))&lt;br /&gt;
ForEachClass(TankClass, UpdateResults(EnvironmentTemperature))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
*The Class instances or Array must be in the &#039;&#039;&#039;global scope&#039;&#039;&#039; and declared before &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is called.&lt;br /&gt;
*ForEachClass is not a true function, it is a convenient &#039;&#039;&#039;Macro&#039;&#039;&#039; that generates a sequence of code at PGM load time. This is why the location of ForEachClass is important relative to declaration of class instances (because it only uses the classes already declared when encountering ForEachClass during load).&lt;br /&gt;
*Use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; to block classes from being used with the ForEachClass macro function. For example for an Array of classes use &amp;quot;ExcludeClass Tanks[0]&amp;quot; alongside &amp;quot;ExcludeWatch Tank[0]&amp;quot; to skip the first class instance in the array with any use of ForEachClass. {{Available139|31388}}&lt;br /&gt;
*A class instance within a class is excluded.&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81783</id>
		<title>Class - Macros</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81783"/>
		<updated>2025-04-01T07:14:28Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* ForEachClass Function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=4}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Class Macros=&lt;br /&gt;
== Macro Parameters ==&lt;br /&gt;
=== Classes Parameter ===&lt;br /&gt;
All of the class macros include a &#039;&#039;Classes&#039;&#039; parameter which is used to define the list of class instances that need to be looped through. There are a number of different ways of defining the list of class instances to be used. If the list of classes includes any class instances marked as excluded using ExcludeClass, this are ignored and excluded from the list of class instances used in the macros.&lt;br /&gt;
&lt;br /&gt;
The different methods for defining &#039;&#039;Classes&#039;&#039; to be used in macros are:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Classes!! Description !! Example&lt;br /&gt;
|-&lt;br /&gt;
|ClassType&lt;br /&gt;
|A named [[#Syntax_for_Class_Definition|Class Type Definition]].&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of the specified class definition.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassList&lt;br /&gt;
|A previously defined [[#ClassList|ClassList]] name.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be from the defined ClassList used.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TanksList, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassInstance1,…}&lt;br /&gt;
|A comma separated list of class instances, that may include indexed classes in class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be as specified in the {} list.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({T1,T2,T3}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({FeedTank,T[5],T[6],T003}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassType1,…}&lt;br /&gt;
|A comma separated list of class type definitions.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of all the specified class definitions.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({TankClass,CSTR_Class}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassArray&lt;br /&gt;
|A class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all the classes in the [[#Syntax_for_Declaring_Class_Instances|Class Array]].&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(T, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== OperationMethod Parameter ===&lt;br /&gt;
Many of the class macros include a &#039;&#039;OperationMethod&#039;&#039; parameter which is used to define the operator method to be applied to the results of the functions or values of the variables for each class instance in the list of class instances that need to be looped through. The [[Operators]] allowed are: &#039;&#039;&#039;+ - * or and bor band bxor&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For example to sum all the values of a class variable use the &amp;quot;+&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Sum = ForEach(+, TankClass, flow).&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
For example to test a bit flag in all classes use the &amp;quot;or&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AnyTanksFull = ForEach(or, TankClass, IsFull()).&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Macros==&lt;br /&gt;
When working with multiple class instances, a number of Macros are available which will perform repetitive functions on each class instance. At load time, a macro is converted into a sequence of normal code. This saves the user from writing out loops or multiple lines of code. It also makes it very easy to add and remove class instances without having to remember to adjust code using the class instances. Macros can work with a predefined ClassList or the classes list can be provided as a parameter for the macro. Class instances can be blocked from use in macros using ExcludeClass.&lt;br /&gt;
&lt;br /&gt;
=== ForEachSub ===&lt;br /&gt;
The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachSub(classes, SubName(..))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Examples:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(TankClass, Exec())&lt;br /&gt;
ClassList MainTanks {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachSub(MainTanks, UpdateResults(AmbientT))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachFn ===&lt;br /&gt;
The macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and storing the result in the specified variable. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039;ForEachFn(ResultVariable, OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Bold text&#039;&#039;&#039;Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachFn(Total, +, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: Total = T1.CalcArea() + T2.CalcArea() + T3.CalcArea()&lt;br /&gt;
&lt;br /&gt;
=== ForEachVar ===&lt;br /&gt;
The macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and storing the result in the specified variable.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVar(ResultVariable, OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(TotalVol, +, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: TotalVol = T1.Volume + T2.Volume + T3.Volume&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarSet ===&lt;br /&gt;
The macro &#039;&#039;ForEachVarSet&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and set the value of a numeric variable (string variables not supported) within the class to be equal to the specified value (or result of an expression).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarSet(Classes, Variable, Expression)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet({T1,T2,T3}, Height, 17)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to T1.Height = 17  T2.Height = 17  T3.Height = 17&lt;br /&gt;
&lt;br /&gt;
== Macro Functions ==&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Macro Function&amp;quot; can be used in expressions similar to a function, unlike a &amp;quot;Macro&amp;quot; which can only be used like a Sub.&lt;br /&gt;
&lt;br /&gt;
=== ForEachFnCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and return the result. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachFnCalc(OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Total = ForEachFnCalc(+, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and return the result.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarCalc(OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TotalVol = ForEachVarCalc(+, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEach ===&lt;br /&gt;
This function macro is the same as ForEachFnCalc or ForEachVarCalc where at load time it auto detects last parameter type and is then equivalent to ForEachFnCalc or ForEachVarCalc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEach(OperationMethod, Classes, FunctName(...)/ClassVariable). &lt;br /&gt;
&lt;br /&gt;
=== ClassCount ===&lt;br /&gt;
The function macro &#039;&#039;ClassCount&#039;&#039; returns the number of class instances in the list of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ClassCount(Classes).&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Count = ClassCount({TankClass})&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AveArea = ForEach(+, {T1,T2,T3}, CalcArea()) / ClassCount({T1,T2,T3})&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Other Functions and Keywords ===&lt;br /&gt;
Other functions and keywords are available when using the Class in the main PGM file. These are described in the [[#How to use the Class (Class Instances)|How to use the Class]] section.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Functions&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ForEachClass&#039;&#039;&#039; Macro Function: used to call subroutines for all instances of the class.  See [[#ForEachClass_Function|ForEachClass Function]] for more details.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEachClass.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Keywords&#039;&#039;&#039; include:&lt;br /&gt;
*&#039;&#039;&#039;ClassGrid&#039;&#039;&#039;: used to display class instances in a table layout. {{Available139|32360}}&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039;: used to define a list of class instances, the list name can then be used when in other functions such as ForEachClass and ClassGrid. {{Available139|32394}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ForEachClass Function ==&lt;br /&gt;
The macro function &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is the original Macro implemented and only option available before {{Available139|32530|n|n}}. The equivalent functionality is available as &#039;&#039;&#039;ForEachSub&#039;&#039;&#039;. Original documentation: &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; provides an efficient method to loop through all instances of a class and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
ForEachClass can be used in a number of ways:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Function Syntax !! Description and Example&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassName,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through ALL instances of the defined Class (class type). &lt;br /&gt;
* All instances include those in global scope class arrays and standalone instances. &lt;br /&gt;
* In the example above, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot; will be called.  (Note, this does not include TankClass instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassNameList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({TankClass,ThickenerClass,WasherClass}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* {{Available139|31388}}&lt;br /&gt;
* Similar to above, but used to loop through ALL instances of all the defined classes in the list. &lt;br /&gt;
* In this example, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot;, &amp;quot;ThickenerClass&amp;quot; and &amp;quot;WasherClass&amp;quot; will be called.  (Note, this does not include class instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassInstanceList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank},UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;. &lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
ClassList ABC {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachClass(ABC,UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*Example 1 above is {{Available139|31388|y}}, example 2 is {{Available139|32394|y}}.&lt;br /&gt;
*Used to loop through the named instances in the specified class instances. &lt;br /&gt;
*In the above example, the function UpdateResults() will be called by Class instance &amp;quot;T1&amp;quot;, &amp;quot;T5&amp;quot;, &amp;quot;FeedTank&amp;quot;, &amp;quot;TankLine.MidTank&amp;quot; and &amp;quot;TankLine.EndTank&amp;quot; only.&lt;br /&gt;
*The ClassInstanceList can be defined using the &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; keyword, available for Build 139.32394 and later.  See [[#Examples Using ClassList|Examples - using ClassList]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassArray,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(Tanks, Init())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through all instances in the specified Array of classes. &lt;br /&gt;
* In the above example, the function Init() will be called by the class instance array &amp;quot;Tanks&amp;quot;.  (Equivalent to calling, Tank[0].init(), Tank[1].init(), etc.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Sub can have any number of parameters, however string parameters are not supported. Where multiple class names (class types) are used, they must all have the same sub with the same parameters. Available for Build 139.31388 and later. Some examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachClass({T1,T5}, SetCalcOptions(true))&lt;br /&gt;
ForEachClass({T2,T3,T4}, SetCalcOptions(false))&lt;br /&gt;
ForEachClass(TankClass, UpdateResults(EnvironmentTemperature))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
*The Class instances or Array must be in the &#039;&#039;&#039;global scope&#039;&#039;&#039; and declared before &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is called.&lt;br /&gt;
*ForEachClass is not a true function, it is a convenient &#039;&#039;&#039;Macro&#039;&#039;&#039; that generates a sequence of code at PGM load time. This is why the location of ForEachClass is important relative to declaration of class instances (because it only uses the classes already declared when encountering ForEachClass during load).&lt;br /&gt;
*Use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; to block classes from being used with the ForEachClass macro function. For example for an Array of classes use &amp;quot;ExcludeClass Tanks[0]&amp;quot; alongside &amp;quot;ExcludeWatch Tank[0]&amp;quot; to skip the first class instance in the array with any use of ForEachClass. {{Available139|31388}}&lt;br /&gt;
*A class instance within a class is excluded.&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81782</id>
		<title>Class - Defining a Class</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Defining_a_Class&amp;diff=81782"/>
		<updated>2025-04-01T07:13:19Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Other Functions and Keywords */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=2}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
== Syntax for Class Definition ==&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top width=20%|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class className&lt;br /&gt;
&lt;br /&gt;
;Variable declaration(s)&lt;br /&gt;
&lt;br /&gt;
;Sub(s) and Function(s)&lt;br /&gt;
&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|width=80%|&lt;br /&gt;
===Syntax for Class Declaration===&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the &#039;&#039;&#039;Class&#039;&#039;&#039; keyword &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the &#039;&#039;&#039;EndClass&#039;&#039;&#039; keyword.&lt;br /&gt;
*&#039;&#039;&#039;className&#039;&#039;&#039;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. See [[#How to use the Class (Class Instances)|How to use the Class]].&lt;br /&gt;
*TextLabel can be used within the class for arranging display of variables in the Access window.&lt;br /&gt;
*ClassAsPageLabel keyword can be used to automatically create tab pages in the Access window based on class instance name.&lt;br /&gt;
&lt;br /&gt;
*Note that Class definitions cannot be nested (i.e. classes cannot be defined within the definition of a class).&lt;br /&gt;
*Various PGM language commands are unavailable within a class definition.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Class Variable Declaration===&lt;br /&gt;
*Variables can be declared within the class, their scope is limited to the class, and they are available to the instance of the class. &lt;br /&gt;
*When declaring variables in a class, the normal variable declaration rules will apply:&lt;br /&gt;
*: The user can define units.&lt;br /&gt;
*: Append * or @ to make the variable visible in the access window, and writeable (*) or read-only (@).&lt;br /&gt;
*: For more information, refer to [[Declaring Variables|Variable declaration]].&lt;br /&gt;
*Variables of type class can be declared within the class. These may be SysCAD PGM classes (e.g. Matrix Class) or user defined classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Syntax for Subs and Functions in a Class===&lt;br /&gt;
&lt;br /&gt;
Any number of functions (of type Sub, Function and StrFunction) can be declared within the class and they are available to the instance of the class. The sequence of functions and variables within a class can be mixed and arranged as required.&lt;br /&gt;
&lt;br /&gt;
Typically, a class will have these three types of subroutine in it:&lt;br /&gt;
*Initialise subroutine&lt;br /&gt;
*Calculation subroutine(s)&lt;br /&gt;
*Execute subroutine&lt;br /&gt;
&lt;br /&gt;
===Special Functions===&lt;br /&gt;
These Special Functions are available for use within class functions and subroutines:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassName()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class type name.  In example below, this will return &amp;quot;CSTR_Class&amp;quot;.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassTag()&amp;lt;/syntaxhighlight&amp;gt; : returns a string of the class instance variable name (tag). This is a particularly useful function when the class instance variable name matches a tag in the model. &lt;br /&gt;
*:For example, we can use &amp;quot;UnitTag = ClassTag()&amp;quot; within an &amp;quot;Init()&amp;quot; Sub for the class. See [[#Example Class Definition File|Example Class Definition File]]&lt;br /&gt;
&lt;br /&gt;
=== Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} The following optional formatting keywords can be added in the Class definition. They are used to help manage how the class instance and its variables are displayed in the Access window. See [[#Class_Instance_Variable_Display_Options|Class Instance Variable Display Options]] for more information.&lt;br /&gt;
&lt;br /&gt;
General keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed as a group in the Access window. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPageLabel&amp;lt;/syntaxhighlight&amp;gt;: {{Available139|31388}} If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed on a new tab page in the Access window, with the page name matching the class instance name. The user does not need to specify PageLabel(xxx) for each class. It is also useful for each class instance in an array of classes appearing on a new tab page. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextLabel&amp;lt;/syntaxhighlight&amp;gt;: If this keyword is included within the class definition, then later when class instances are declared they are automatically displayed with a text label (heading) in the Access window, with the text label matching the class instance name.&lt;br /&gt;
&lt;br /&gt;
Grid display keywords:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
Instead of using the above formatting keywords within the class definition, they can be included within {} when defining the class name. The full keyword or shortened formats can be used. These are ClassAsPageLabel|AsPageLabel|pl, ClassAsTextLabel|AsTextLabel|tl, ClassAsGroup|AsGroup|g, ClassGridColumnWidth|ColumnWidth|Width|cw, ClassGridMaxColumns|MaxColumns|mc, ClassGridHideComment|HideComment|hc ClassGridHideText|HideText|ht. &amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;class TankClass{g,pl,cw(12),mc(6)}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax for Class Instance Definition==&lt;br /&gt;
Once the Class has been defined (template complete), the user can include this named class definition (template) in pgm files to declare any number of class instances. Class instances are then used in subsequent to code to perform calculation acting on the individual class instances. Class instances can be declared &#039;&#039;&#039;individually&#039;&#039;&#039; (in the same way normal data variables are declared) or as an &#039;&#039;&#039;array&#039;&#039;&#039; of class instances:&lt;br /&gt;
* Example of individually named class instances: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank_1, Tank_2&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring_Class_Instances|Example - declaring class instances]].&lt;br /&gt;
* Example of class array: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;CSTR_Class Tank[3]&amp;lt;/syntaxhighlight&amp;gt;  See [[#Declaring Class Instances in an array|Example - Declaring Class Instances in an array]].&lt;br /&gt;
&lt;br /&gt;
===Syntax for Interacting with Class Instances===&lt;br /&gt;
Once the class instance has been declared, user can access class variable tags and perform the Class functions or subroutine.  &lt;br /&gt;
&lt;br /&gt;
* Setting a value to a data member of an instance. &lt;br /&gt;
*:For example, we can set the UnitTag for class instance &amp;quot;TankA&amp;quot; during the &amp;quot;InitialiseSolution()&amp;quot; subroutine: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankA.UnitTag = &amp;quot;TANK_A&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;.   &lt;br /&gt;
* Retrieving the value of a data member of an instance.  &lt;br /&gt;
*:For example: we can retrieve a value from a class function and assign it to a variable: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ReactionExtent = TankA.CuLeachExtent&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Retrieving the value returned by a member function of an instance. &lt;br /&gt;
*:For example: we can get the species index of water from the [[Species Database Class]]: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;SpeciesIndex = SDB.FindSpecies(&amp;quot;H2O(l)&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* Performing Class Function / subroutine calculations.&lt;br /&gt;
*:For example, we can perform the Exec() function for class instances Tank_A and Tank_B:  &lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_A.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Tank_B.Exec()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If user have declared many class instances, it will be quite tedious to define each function call separately.  To execute some of these functions more efficiently, we have added some special &amp;quot;ForEach&amp;quot; [[#Class Macros|macros]]. For example:&lt;br /&gt;
*&#039;&#039;&#039;ForEachSub&#039;&#039;&#039; (previously ForEachClass) Macro Function: used to call subroutines for all instances of the class.&lt;br /&gt;
*&#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; Used to block class from use in ForEach macro.  Commonly used to block instance at index 0 in an array of classes.&lt;br /&gt;
*&#039;&#039;&#039;ClassList&#039;&#039;&#039; Used to define a list of class instances as aa single variable and then use this with ForEach Macros and ForEach Macro Functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Class Instance Variable Display Options ==&lt;br /&gt;
&lt;br /&gt;
When class instances are declared, any watched variables will be available on the access window.  &lt;br /&gt;
*When declaring the class instances, &#039;&#039;&#039;*&#039;&#039;&#039; or &#039;&#039;&#039;@&#039;&#039;&#039; CANNOT be appended to the class instance name.&lt;br /&gt;
*Class instances are automatically added to the access window.&lt;br /&gt;
&lt;br /&gt;
=== ExcludeWatch ===&lt;br /&gt;
To hide a specific class instance from the access window display, use &#039;&#039;&#039;ExcludeWatch&#039;&#039;&#039; followed by one or more ClassNames. A comma separated list of any number of class instances, including indexed class instances of a class array can be listed.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch ClassInstance1,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ExcludeWatch Tank[0]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ExcludeWatch is primarily used for hiding the the class at index 0 within a class array as shown in above example. From Build 139.32530 it is possible to define this when declaring the class array using {ExcludeWatchZero} or {ewz}. However because it is very common to use both ExcludeClass and ExcludeWatch, then use {ExcludeZero} or {ez}. For example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;const long TankCount = 11&lt;br /&gt;
TankClass T[TankCount]&lt;br /&gt;
ExcludeWatch T[0]&lt;br /&gt;
ExcludeClass T[0]&lt;br /&gt;
;From Build 139.32530 the above can be replaced by&lt;br /&gt;
TankClass T[TankCount]{ewz,ecz} ;or in full {ExcludeWatchZero,ExcludeClassZero}&lt;br /&gt;
;or simply the common combined form:&lt;br /&gt;
TankClass T[TankCount]{ExcludeZero} ;using full keyword&lt;br /&gt;
TankClass T[TankCount]{ez}          ;using abbreviated keyword&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ClassComment ===&lt;br /&gt;
After class instances have been declared, &#039;&#039;&#039;ClassComment&#039;&#039;&#039; can be used to specify short text comments for Class Instances (similar to text comment for individual variables). A comma separated list of any number of class instances (including indexed class array instances) with text string in quotes (&amp;quot;) can be listed. The display of the comment in the Access window depends on use of ClassAsGroup and if class is shown in Grid.&amp;lt;br&amp;gt;&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment ClassInstance1 &amp;quot;String1&amp;quot;,...&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassComment T[1] &amp;quot;Feed tank&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ClassComment is primarily used for specifying comments for class instances within a class array as shown in above example. In most cases it is more common to include the comment with the declaration of the individual class instance.&amp;lt;br&amp;gt;&lt;br /&gt;
For example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TankClass T1{&amp;quot;Feed Tank&amp;quot;}, T2{&amp;quot;Acid Tank&amp;quot;}, T3{&amp;quot;Tank 300-A012&amp;quot;}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class variables for class instances should be displayed in the Access window. General formatting options:&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsGroup&amp;lt;/syntaxhighlight&amp;gt; keyword (recommended) to use the ClassName... group heading for each class instance (and all the variables don&#039;t have the repeated ClassName.xxx). This is particularly useful together with a ClassComment for the class instances where the comment is shown in the group heading, displayed as: &amp;quot;ClassName (comment) ...&amp;quot;.&lt;br /&gt;
* Use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsPagelabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display one Class instance per tab page.&lt;br /&gt;
* use &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassAsTextlabel&amp;lt;/syntaxhighlight&amp;gt; keyword to display the class name as a text label heading to &amp;quot;separate&amp;quot; the class instances.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid ===&lt;br /&gt;
{{Available139|32530}} With the keyword &#039;&#039;&#039;ClassGrid&#039;&#039;&#039;, class instances of user defined class types can be displayed in Grids (Tables) in the Access window with the class instances as columns. The ClassGrid keyword is used anywhere after class instances are declared to control where the grids are displayed. It is also possible to use the keyword when [[#Syntax_for_Declaring_Class_Instances|declaring the class instances]].&lt;br /&gt;
Syntax is: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Classes&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Where &#039;&#039;Classes&#039;&#039; is a list of class instances of the same class definition. &#039;&#039;Classes&#039;&#039; can be specified in a number of different methods such as using a previously defined ClassList or list of classes similar to [[#Classes_Parameter|Classes Parameter]] in ForEach macros.&amp;lt;br&amp;gt;&lt;br /&gt;
Example (list of class instances): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {T1,T2,T3}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;T1,T2,T3&#039;&#039; are previously defined instances of the same class definition)&amp;lt;br&amp;gt;&lt;br /&gt;
Example (ClassList): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid L1&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;L1&#039;&#039; is a previously defined [[#ClassList|ClassList]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class definition type): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid {TankClass}&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;TankClass&#039;&#039; is a previously defined [[##Syntax_for_Class_Definition|Class Definition]])&amp;lt;br&amp;gt;&lt;br /&gt;
Example (class array): &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGrid Tanks&amp;lt;/syntaxhighlight&amp;gt;  (where &#039;&#039;Tanks&#039;&#039; is a previously defined [[#Syntax_for_Declaring_Class_Instances|Class Array]])&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The width of each column can be controlled with the &#039;&#039;&#039;ClassGridColumnWidth&#039;&#039;&#039; keyword in the class definition.&lt;br /&gt;
* The maximum number of columns in a grid is controlled with the &#039;&#039;&#039;ClassGridMaxColumns&#039;&#039;&#039; keyword in the class definition. Additional grids are automatically created when there is a larger number of class instances.&lt;br /&gt;
* TextLabels within the class grid are shown as row separators, however blank lines and multiple text lines are ignored (only the last TextLabel in a sequence is shown). All text in a grid can be hidden if using keyword &#039;&#039;&#039;ClassGridHideText&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If comments are used for class instances, these are shown as text for each column in first row of grid. This can be disabled using keyword &#039;&#039;&#039;ClassGridHideComment&#039;&#039;&#039; in the class definition.&lt;br /&gt;
* If option ClassGridPageLabel is used in class definition, then the grid is displayed on a new tab page in the Access window.&lt;br /&gt;
* The use of ClassGrid allows positioning of display of the grid in Access window to be at any point after the declaration of class instances. To display the grid at the point of declaring the classes, use the {Grid} option or # symbol.&lt;br /&gt;
* Only user defined classes can be used in the ClassGrid. Predefined PGM class types (TagSelect, Matrix, etc.) cannot be used with ClassGrid.&lt;br /&gt;
* A class instance can only be displayed once in a grid.&lt;br /&gt;
&lt;br /&gt;
=== ClassGrid Formatting Keywords ===&lt;br /&gt;
{{Available139|32530}} A number of different keywords in the class definition can be used to manage how the class grid is displayed in the Access window:&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridColumnWidth Width&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the default width (14) of each column displayed in a class grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridMaxColumns MaxColumns&amp;lt;/syntaxhighlight&amp;gt;: Use this to change the maximum number of columns (10) allowed before a new grid is automatically created.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideComment&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of class instance comments, that are normally displayed in the first row of the grid.&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassGridHideText&amp;lt;/syntaxhighlight&amp;gt;: Use this to hide the display of all TextLabels shown as text between rows in the grid.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
{|&lt;br /&gt;
|Valign=top Width=35% rowspan=3|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
;Class PGM&lt;br /&gt;
Class TankClass&lt;br /&gt;
   ;ClassAsPageLabel&lt;br /&gt;
   ;ClassAsTextLabel&lt;br /&gt;
   ;ClassAsGroup&lt;br /&gt;
   ;ClassGridColumnWidth 8 ;default is 14&lt;br /&gt;
   ;ClassGridMaxColumns 3  ;default is 10&lt;br /&gt;
   ;other code here....&lt;br /&gt;
   String UnitTag{Tag}@&lt;br /&gt;
   Real   Volume*&amp;lt;&amp;lt;100&amp;gt;&amp;gt;(&amp;quot;Vol&amp;quot;, &amp;quot;m^3&amp;quot;)&lt;br /&gt;
   Real	  Height*&amp;lt;&amp;lt;1&amp;gt;&amp;gt;(&amp;quot;L&amp;quot;, &amp;quot;m&amp;quot;)&lt;br /&gt;
   Real   ResidenceTime*(&amp;quot;Time&amp;quot;, &amp;quot;h&amp;quot;)&lt;br /&gt;
   TextLabel()&lt;br /&gt;
EndClass&lt;br /&gt;
&lt;br /&gt;
;Main PGM&lt;br /&gt;
PageLabel(&amp;quot;Tanks&amp;quot;)&lt;br /&gt;
TextLabel(,)&lt;br /&gt;
TankClass Tank1, Tank2&lt;br /&gt;
;TankClass Tank[7]&lt;br /&gt;
;ClassGrid TankClass&lt;br /&gt;
;ExcludeWatch Tank[0]&lt;br /&gt;
;ExcludeClass Tank[0]&lt;br /&gt;
$&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: The examples presented to the right uses different options from the above code (currently marked with ;).&lt;br /&gt;
&lt;br /&gt;
|Valign=top|[[image:PGM_ClassDisplay.png|thumb|Using PageLabel keyword only]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsPageLabel.png|thumb|Using ClassAsPageLabel]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassAsTextLabel.png|thumb|Using ClassAsTextLabel]]&lt;br /&gt;
|Valign=top|[[image:PGM_Classgroup.png|thumb|Using ClassAsGroup]]&lt;br /&gt;
|-&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid.png|thumb|Using ClassGrid]]&lt;br /&gt;
|Valign=top|[[image:PGM_ClassGrid2.png|thumb|Using ClassGrid with custom width]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Class Syntax Summary==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=10%|Function !! width=20%|Function Syntax !! width=35%|Data Type !! width=45%|Description / Examples / Notes&lt;br /&gt;
|-&lt;br /&gt;
| Declaring a Class&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
Class className&lt;br /&gt;
;Class code&lt;br /&gt;
EndClass &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Class&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must begin with the word &#039;&#039;&#039;Class&#039;&#039;&#039;&lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;className&amp;lt;/syntaxhighlight&amp;gt;: A globally unique class type name must be provided. This is later used as a &amp;quot;data type&amp;quot; when declaring instances of classes of this class type. &lt;br /&gt;
*&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;EndClass&amp;lt;/syntaxhighlight&amp;gt;: The class declaration must end with the word &#039;&#039;&#039;EndClass&#039;&#039;&#039;&lt;br /&gt;
|&lt;br /&gt;
This is the logic used to declare and name the class. All of the class logic will be contained by these statements.&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=2|Class Variable Declaration&lt;br /&gt;
|&lt;br /&gt;
|rowspan=2|&lt;br /&gt;
*Variables can be declared within a class.&lt;br /&gt;
*Each declared variable within a class will exist for each instance of that class.&lt;br /&gt;
*Their scope is limited to that class.&lt;br /&gt;
|rowspan=2|&lt;br /&gt;
Normal variable declarition rules apply to these variables:&lt;br /&gt;
*The user can define units&lt;br /&gt;
*Append * or @ to make th variable visable in the access window and writable (*) or read-only (@)&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
variable = GetDynTag(&amp;quot;full tag&amp;quot;)&lt;br /&gt;
variable = GetDynTag(string)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|Getting Tag from SysCAD &amp;lt;br&amp;gt; &#039;&#039;&#039;Alternative Syntax&#039;&#039;&#039;&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
variable = GetDynStrTag(string)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
*&#039;&#039;&#039;variable:&#039;&#039;&#039; This should be a [[PGM Programming and Conventions#Data Types| STR]] variable type&lt;br /&gt;
*&#039;&#039;&#039;string&#039;&#039;&#039;: is a variable of type [[PGM Programming and Conventions#Data Types| STR]] that refers to a tag.  A conversion may also be specified within the &#039;&#039;&#039;string&#039;&#039;&#039;.  See [[PGM Programming and Conventions#Tags |Tags]] for the correct tag syntax.&lt;br /&gt;
|&lt;br /&gt;
*returns the Tag name of the parameter, referred to by the tag contained in &#039;&#039;&#039;string&#039;&#039;&#039;.&lt;br /&gt;
*See [[#Examples|Example 2]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Examples&amp;diff=81778</id>
		<title>Class - Examples</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Examples&amp;diff=81778"/>
		<updated>2025-03-31T22:29:56Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=5}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Class Examples=&lt;br /&gt;
==Class Declaration Example==&lt;br /&gt;
*A very condensed extract of the CSTR_Class PGM file is presented below to explain the structure and use of the Class definition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;Class CSTR_Class&lt;br /&gt;
 ClassAsPageLabel           ;example of Special Keyword&lt;br /&gt;
 ;... Various Variable Definitions.....&lt;br /&gt;
 String     UnitTag{tag}@&lt;br /&gt;
 Real       TankVolume*(&amp;quot;Vol&amp;quot;,&amp;quot;m^3&amp;quot;)&amp;lt;&amp;lt;300&amp;gt;&amp;gt;&lt;br /&gt;
 ;... Various Variable Definitions.....&lt;br /&gt;
&lt;br /&gt;
 Sub Init()&lt;br /&gt;
   UnitTag = ClassTag()     ; example of Special Function&lt;br /&gt;
   [concatenate(UnitTag, &amp;quot;.ResTime.Volume (m^3)&amp;quot;)] = TankVolume&lt;br /&gt;
 EndSub&lt;br /&gt;
 &lt;br /&gt;
 Sub CalculateCSTR()&lt;br /&gt;
  ;......Various Calculation Code .....&lt;br /&gt;
 EndSub   &lt;br /&gt;
 &lt;br /&gt;
 Sub Exec()&lt;br /&gt;
   ;......Various Calculation Code .....&lt;br /&gt;
   CalculateCSTR()                           ;Example of calling a predefined subroutine within a subroutine.&lt;br /&gt;
   ;......Various Calculation Code .....&lt;br /&gt;
 EndSub&lt;br /&gt;
EndClass&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# The name of the Class (or template) is called CSTR_Class.&lt;br /&gt;
# All the variables that are associated with the CSTR_Class are defined.  (The full PGM file is available in the [[Example_25_Gold|Gold distributed example project]])&lt;br /&gt;
# Nested functions are allowed within a class, for example Sub &amp;quot;CalculateCSTR&amp;quot; is called inside the Sub &amp;quot;Exec()&amp;quot;&lt;br /&gt;
# In summary, the Class(template) &amp;quot;CSTR_Class&amp;quot; contains a number of calculations and a number of Set Value Commands.&lt;br /&gt;
&lt;br /&gt;
==Other Examples HERE==&lt;br /&gt;
&lt;br /&gt;
== Example User Defined Classes ==&lt;br /&gt;
&lt;br /&gt;
# [[Example 25 Gold|Gold Project]] - demonstrates the use of Classes in the CSTR pgm file.  This is used to calculate the gold and copper leaching and adsorption values in a number of individual tanks.&lt;br /&gt;
# [[Example_-_02Feature_Projects#Lime_Preparation_.28Makeup.29_Project|Lime Preparation (Makeup) Example]] - demonstrates the use of two user defined Classes: [[PGM Examples - PGM Class to Set Species Splits |Set Species Splits]] and [[PGM Example - PGM Class to assist with solving sensitive PID control loops|Optimise Controller]].&lt;br /&gt;
# [[Example_-_04SizeDistribution_Projects#Milling_and_Flotation_Project|Milling and Flotation Project]] - demonstrate the use of Classes to display flotation recoveries at the end of project solve.&lt;br /&gt;
# [[Example_-_04SizeDistribution_Projects#Milling and Magnetic Separation Project|Milling and Magnetic Separation Project]] - demonstrate the use of Classes to display cyclone splits and magnetic separator recoveries.&lt;br /&gt;
# [[Example_-_04SizeDistribution_Projects|Size Distribution Project]] - demonstrate the use of Classes to display some cyclone split information.&lt;br /&gt;
# [[Digestion_Projects#Example_1:_Digestion with Direct Heating|Digestion with Direct Heating]] - demonstrates the use of Classes to calculate user defined properties.&lt;br /&gt;
# [[Ammonia_Projects#Example_1:_Demo_Ammonia_Project|Demo Ammonia Project]] - demonstrates the use of Classes to calculate water shift.&lt;br /&gt;
# [[Example_Potash_Projects#SOP_Example_Project|SOP Example Project]] - demonstrate the use of Classes to add rainfall and evaporation to the tank model (emulating a pond).&lt;br /&gt;
# [[Example_65_Smelting#FerroManganese_Furnace_Example|FerroManganese Furnace Example Project]] - demonstrates use of Classes to set flow in feeders, perform heat loss calculations, and  to calculate and set reactions extents.&lt;br /&gt;
# See [[Example_PGM_Files#PGM_Files_using_Class_and_Functions | Example Class Files]] for more examples of user defined class definitions.&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81777</id>
		<title>Class - Macros</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81777"/>
		<updated>2025-03-31T22:26:57Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Macros */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=4}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Class Macros=&lt;br /&gt;
== Macro Parameters ==&lt;br /&gt;
=== Classes Parameter ===&lt;br /&gt;
All of the class macros include a &#039;&#039;Classes&#039;&#039; parameter which is used to define the list of class instances that need to be looped through. There are a number of different ways of defining the list of class instances to be used. If the list of classes includes any class instances marked as excluded using ExcludeClass, this are ignored and excluded from the list of class instances used in the macros.&lt;br /&gt;
&lt;br /&gt;
The different methods for defining &#039;&#039;Classes&#039;&#039; to be used in macros are:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Classes!! Description !! Example&lt;br /&gt;
|-&lt;br /&gt;
|ClassType&lt;br /&gt;
|A named [[#Syntax_for_Class_Definition|Class Type Definition]].&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of the specified class definition.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassList&lt;br /&gt;
|A previously defined [[#ClassList|ClassList]] name.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be from the defined ClassList used.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TanksList, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassInstance1,…}&lt;br /&gt;
|A comma separated list of class instances, that may include indexed classes in class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be as specified in the {} list.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({T1,T2,T3}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({FeedTank,T[5],T[6],T003}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassType1,…}&lt;br /&gt;
|A comma separated list of class type definitions.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of all the specified class definitions.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({TankClass,CSTR_Class}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassArray&lt;br /&gt;
|A class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all the classes in the [[#Syntax_for_Declaring_Class_Instances|Class Array]].&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(T, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== OperationMethod Parameter ===&lt;br /&gt;
Many of the class macros include a &#039;&#039;OperationMethod&#039;&#039; parameter which is used to define the operator method to be applied to the results of the functions or values of the variables for each class instance in the list of class instances that need to be looped through. The [[Operators]] allowed are: &#039;&#039;&#039;+ - * or and bor band bxor&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For example to sum all the values of a class variable use the &amp;quot;+&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Sum = ForEach(+, TankClass, flow).&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
For example to test a bit flag in all classes use the &amp;quot;or&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AnyTanksFull = ForEach(or, TankClass, IsFull()).&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Class Macros==&lt;br /&gt;
When working with multiple class instances, a number of Macros are available which will perform repetitive functions on each class instance. At load time, a macro is converted into a sequence of normal code. This saves the user from writing out loops or multiple lines of code. It also makes it very easy to add and remove class instances without having to remember to adjust code using the class instances. Macros can work with a predefined ClassList or the classes list can be provided as a parameter for the macro. Class instances can be blocked from use in macros using ExcludeClass.&lt;br /&gt;
&lt;br /&gt;
=== ForEachSub ===&lt;br /&gt;
The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachSub(classes, SubName(..))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Examples:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(TankClass, Exec())&lt;br /&gt;
ClassList MainTanks {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachSub(MainTanks, UpdateResults(AmbientT))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachFn ===&lt;br /&gt;
The macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and storing the result in the specified variable. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039;ForEachFn(ResultVariable, OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Bold text&#039;&#039;&#039;Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachFn(Total, +, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: Total = T1.CalcArea() + T2.CalcArea() + T3.CalcArea()&lt;br /&gt;
&lt;br /&gt;
=== ForEachVar ===&lt;br /&gt;
The macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and storing the result in the specified variable.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVar(ResultVariable, OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(TotalVol, +, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: TotalVol = T1.Volume + T2.Volume + T3.Volume&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarSet ===&lt;br /&gt;
The macro &#039;&#039;ForEachVarSet&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and set the value of a numeric variable (string variables not supported) within the class to be equal to the specified value (or result of an expression).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarSet(Classes, Variable, Expression)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet({T1,T2,T3}, Height, 17)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to T1.Height = 17  T2.Height = 17  T3.Height = 17&lt;br /&gt;
&lt;br /&gt;
== Macro Functions ==&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Macro Function&amp;quot; can be used in expressions similar to a function, unlike a &amp;quot;Macro&amp;quot; which can only be used like a Sub.&lt;br /&gt;
&lt;br /&gt;
=== ForEachFnCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and return the result. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachFnCalc(OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Total = ForEachFnCalc(+, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and return the result.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEachVarCalc(OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TotalVol = ForEachVarCalc(+, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEach ===&lt;br /&gt;
This function macro is the same as ForEachFnCalc or ForEachVarCalc where at load time it auto detects last parameter type and is then equivalent to ForEachFnCalc or ForEachVarCalc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ForEach(OperationMethod, Classes, FunctName(...)/ClassVariable). &lt;br /&gt;
&lt;br /&gt;
=== ClassCount ===&lt;br /&gt;
The function macro &#039;&#039;ClassCount&#039;&#039; returns the number of class instances in the list of classes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Syntax is:&#039;&#039;&#039; ClassCount(Classes).&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Count = ClassCount({TankClass})&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example:&#039;&#039;&#039; &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AveArea = ForEach(+, {T1,T2,T3}, CalcArea()) / ClassCount({T1,T2,T3})&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ForEachClass Function ==&lt;br /&gt;
The macro function &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is the original Macro implemented and only option available before {{Available139|32530|n|n}}. The equivalent functionality is available as &#039;&#039;&#039;ForEachSub&#039;&#039;&#039;. Original documentation: &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; provides an efficient method to loop through all instances of a class and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
ForEachClass can be used in a number of ways:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Function Syntax !! Description and Example&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassName,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through ALL instances of the defined Class (class type). &lt;br /&gt;
* All instances include those in global scope class arrays and standalone instances. &lt;br /&gt;
* In the example above, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot; will be called.  (Note, this does not include TankClass instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassNameList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({TankClass,ThickenerClass,WasherClass}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* {{Available139|31388}}&lt;br /&gt;
* Similar to above, but used to loop through ALL instances of all the defined classes in the list. &lt;br /&gt;
* In this example, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot;, &amp;quot;ThickenerClass&amp;quot; and &amp;quot;WasherClass&amp;quot; will be called.  (Note, this does not include class instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassInstanceList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank},UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;. &lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
ClassList ABC {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachClass(ABC,UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*Example 1 above is {{Available139|31388|y}}, example 2 is {{Available139|32394|y}}.&lt;br /&gt;
*Used to loop through the named instances in the specified class instances. &lt;br /&gt;
*In the above example, the function UpdateResults() will be called by Class instance &amp;quot;T1&amp;quot;, &amp;quot;T5&amp;quot;, &amp;quot;FeedTank&amp;quot;, &amp;quot;TankLine.MidTank&amp;quot; and &amp;quot;TankLine.EndTank&amp;quot; only.&lt;br /&gt;
*The ClassInstanceList can be defined using the &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; keyword, available for Build 139.32394 and later.  See [[#Examples Using ClassList|Examples - using ClassList]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassArray,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(Tanks, Init())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through all instances in the specified Array of classes. &lt;br /&gt;
* In the above example, the function Init() will be called by the class instance array &amp;quot;Tanks&amp;quot;.  (Equivalent to calling, Tank[0].init(), Tank[1].init(), etc.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Sub can have any number of parameters, however string parameters are not supported. Where multiple class names (class types) are used, they must all have the same sub with the same parameters. Available for Build 139.31388 and later. Some examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachClass({T1,T5}, SetCalcOptions(true))&lt;br /&gt;
ForEachClass({T2,T3,T4}, SetCalcOptions(false))&lt;br /&gt;
ForEachClass(TankClass, UpdateResults(EnvironmentTemperature))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
*The Class instances or Array must be in the &#039;&#039;&#039;global scope&#039;&#039;&#039; and declared before &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is called.&lt;br /&gt;
*ForEachClass is not a true function, it is a convenient &#039;&#039;&#039;Macro&#039;&#039;&#039; that generates a sequence of code at PGM load time. This is why the location of ForEachClass is important relative to declaration of class instances (because it only uses the classes already declared when encountering ForEachClass during load).&lt;br /&gt;
*Use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; to block classes from being used with the ForEachClass macro function. For example for an Array of classes use &amp;quot;ExcludeClass Tanks[0]&amp;quot; alongside &amp;quot;ExcludeWatch Tank[0]&amp;quot; to skip the first class instance in the array with any use of ForEachClass. {{Available139|31388}}&lt;br /&gt;
*A class instance within a class is excluded.&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
	<entry>
		<id>https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81776</id>
		<title>Class - Macros</title>
		<link rel="alternate" type="text/html" href="https://help.syscad.net/index.php?title=Class_-_Macros&amp;diff=81776"/>
		<updated>2025-03-31T22:13:09Z</updated>

		<summary type="html">&lt;p&gt;Eleanor.McFeaters: /* Class Macros */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:PGM]]&lt;br /&gt;
{{Navigation|[[PGMs]]|altname=Classes}}&lt;br /&gt;
{{Function Header Tabs |currentpage=8}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Related Links:&#039;&#039;&#039; [[Example_PGM_Files#User_Defined_Class_and_Functions|User Defined Class and Functions]], [[Example_PGM_Files#User_Defined_Class_and_Functions|Example PGM Files]] &lt;br /&gt;
{{Class Header Tabs|currentpage=4}}&lt;br /&gt;
&#039;&#039;&#039;Global Predefined Class Instances:&#039;&#039;&#039; [[Species Database Class]], [[Particle Size Definition Class]], [[Plant Model Class]]&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Predefined Classes:&#039;&#039;&#039; [[Array Class]], [[StrArray Class]], [[Matrix Class]], [[TagSelect Class]], [[Noise Class]], [[TimeClass]]&lt;br /&gt;
----&lt;br /&gt;
{{TOC}}&lt;br /&gt;
&lt;br /&gt;
=Class Macros=&lt;br /&gt;
When working with multiple class instances, a number of Macros are available which will perform repetitive functions on each class instance. At load time, a macro is converted into a sequence of normal code. This saves the user from writing out loops or multiple lines of code. It also makes it very easy to add and remove class instances without having to remember to adjust code using the class instances. Macros can work with a predefined ClassList or the classes list can be provided as a parameter for the macro. Class instances can be blocked from use in macros using ExcludeClass.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== ForEachSub ===&lt;br /&gt;
The macro &#039;&#039;ForEachSub&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
Syntax is: ForEachSub(classes, SubName(..))&amp;lt;br&amp;gt;&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachSub(TankClass, Exec())&lt;br /&gt;
ClassList MainTanks {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachSub(MainTanks, UpdateResults(AmbientT))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachFn ===&lt;br /&gt;
The macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and storing the result in the specified variable. &lt;br /&gt;
&lt;br /&gt;
Syntax is:ForEachFn(ResultVariable, OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachFn(Total, +, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: Total = T1.CalcArea() + T2.CalcArea() + T3.CalcArea()&lt;br /&gt;
&lt;br /&gt;
=== ForEachVar ===&lt;br /&gt;
The macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and storing the result in the specified variable.&lt;br /&gt;
&lt;br /&gt;
Syntax is: ForEachVar(ResultVariable, OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVar(TotalVol, +, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to: TotalVol = T1.Volume + T2.Volume + T3.Volume&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarSet ===&lt;br /&gt;
The macro &#039;&#039;ForEachVarSet&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and set the value of a numeric variable (string variables not supported) within the class to be equal to the specified value (or result of an expression).&lt;br /&gt;
&lt;br /&gt;
Syntax is: ForEachVarSet(Classes, Variable, Expression)&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachVarSet({T1,T2,T3}, Height, 17)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
which is equivalent to T1.Height = 17  T2.Height = 17  T3.Height = 17&lt;br /&gt;
&lt;br /&gt;
== Macro Functions ==&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Macro Function&amp;quot; can be used in expressions similar to a function, unlike a &amp;quot;Macro&amp;quot; which can only be used like a Sub.&lt;br /&gt;
&lt;br /&gt;
=== ForEachFnCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachFn&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and call a Function within the class performing the specified operation and return the result. &lt;br /&gt;
&lt;br /&gt;
Syntax is: ForEachFnCalc(OperationMethod, Classes, FunctName(...))&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Total = ForEachFnCalc(+, {T1,T2,T3}, CalcArea())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEachVarCalc ===&lt;br /&gt;
The function macro &#039;&#039;ForEachVar&#039;&#039; provides an efficient method to loop through all class instances from a list of classes and using a variable within the class performing the specified operation and return the result.&lt;br /&gt;
&lt;br /&gt;
Syntax is: ForEachVarCalc(OperationMethod, Classes, ClassVariable)&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;TotalVol = ForEachVarCalc(+, {T1,T2,T3}, Volume)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ForEach ===&lt;br /&gt;
This function macro is the same as ForEachFnCalc or ForEachVarCalc where at load time it auto detects last parameter type and is then equivalent to ForEachFnCalc or ForEachVarCalc.&lt;br /&gt;
&lt;br /&gt;
Syntax is: ForEach(OperationMethod, Classes, FunctName(...)/ClassVariable). &lt;br /&gt;
&lt;br /&gt;
=== ClassCount ===&lt;br /&gt;
The function macro &#039;&#039;ClassCount&#039;&#039; returns the number of class instances in the list of classes.&lt;br /&gt;
&lt;br /&gt;
Syntax is: ClassCount(Classes).&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Count = ClassCount({TankClass})&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Example: &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AveArea = ForEach(+, {T1,T2,T3}, CalcArea()) / ClassCount({T1,T2,T3})&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Macro Parameters ==&lt;br /&gt;
=== Classes Parameter ===&lt;br /&gt;
All of the class macros include a &#039;&#039;Classes&#039;&#039; parameter which is used to define the list of class instances that need to be looped through. There are a number of different ways of defining the list of class instances to be used. If the list of classes includes any class instances marked as excluded using ExcludeClass, this are ignored and excluded from the list of class instances used in the macros.&lt;br /&gt;
&lt;br /&gt;
The different methods for defining &#039;&#039;Classes&#039;&#039; to be used in macros are:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Classes!! Description !! Example&lt;br /&gt;
|-&lt;br /&gt;
|ClassType&lt;br /&gt;
|A named [[#Syntax_for_Class_Definition|Class Type Definition]].&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of the specified class definition.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassList&lt;br /&gt;
|A previously defined [[#ClassList|ClassList]] name.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be from the defined ClassList used.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(TanksList, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassInstance1,…}&lt;br /&gt;
|A comma separated list of class instances, that may include indexed classes in class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be as specified in the {} list.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({T1,T2,T3}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({FeedTank,T[5],T[6],T003}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|{ClassType1,…}&lt;br /&gt;
|A comma separated list of class type definitions.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all class instances from global scope, up to this point in the code, of all the specified class definitions.&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub({TankClass,CSTR_Class}, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|ClassArray&lt;br /&gt;
|A class array.&amp;lt;br&amp;gt;&lt;br /&gt;
List used will be all the classes in the [[#Syntax_for_Declaring_Class_Instances|Class Array]].&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachSub(T, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== OperationMethod Parameter ===&lt;br /&gt;
Many of the class macros include a &#039;&#039;OperationMethod&#039;&#039; parameter which is used to define the operator method to be applied to the results of the functions or values of the variables for each class instance in the list of class instances that need to be looped through. The [[Operators]] allowed are: &#039;&#039;&#039;+ - * or and bor band bxor&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For example to sum all the values of a class variable use the &amp;quot;+&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;Sum = ForEach(+, TankClass, flow).&amp;lt;/syntaxhighlight&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
For example to test a bit flag in all classes use the &amp;quot;or&amp;quot; operator. &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;AnyTanksFull = ForEach(or, TankClass, IsFull()).&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ForEachClass Function ==&lt;br /&gt;
The macro function &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is the original Macro implemented and only option available before {{Available139|32530|n|n}}. The equivalent functionality is available as &#039;&#039;&#039;ForEachSub&#039;&#039;&#039;. Original documentation: &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; provides an efficient method to loop through all instances of a class and call a Sub within the class. &lt;br /&gt;
&lt;br /&gt;
ForEachClass can be used in a number of ways:&lt;br /&gt;
{|class=wikitable&lt;br /&gt;
!Function Syntax !! Description and Example&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassName,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(TankClass, Exec())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through ALL instances of the defined Class (class type). &lt;br /&gt;
* All instances include those in global scope class arrays and standalone instances. &lt;br /&gt;
* In the example above, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot; will be called.  (Note, this does not include TankClass instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassNameList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({TankClass,ThickenerClass,WasherClass}, Exec())&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
* {{Available139|31388}}&lt;br /&gt;
* Similar to above, but used to loop through ALL instances of all the defined classes in the list. &lt;br /&gt;
* In this example, function exec() for all the declared class instances of &amp;quot;TankClass&amp;quot;, &amp;quot;ThickenerClass&amp;quot; and &amp;quot;WasherClass&amp;quot; will be called.  (Note, this does not include class instances declared after this line.  See [[#Using ForEachClass with multiple class declarations|Example - Using ForEachClass with multiple class declarations]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({ClassInstanceList},SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass({T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank},UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;. &lt;br /&gt;
#&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;&lt;br /&gt;
ClassList ABC {T1,T5,FeedTank,TankLine.MidTank,TankLine.EndTank}&lt;br /&gt;
ForEachClass(ABC,UpdateResults())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*Example 1 above is {{Available139|31388|y}}, example 2 is {{Available139|32394|y}}.&lt;br /&gt;
*Used to loop through the named instances in the specified class instances. &lt;br /&gt;
*In the above example, the function UpdateResults() will be called by Class instance &amp;quot;T1&amp;quot;, &amp;quot;T5&amp;quot;, &amp;quot;FeedTank&amp;quot;, &amp;quot;TankLine.MidTank&amp;quot; and &amp;quot;TankLine.EndTank&amp;quot; only.&lt;br /&gt;
*The ClassInstanceList can be defined using the &amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ClassList&amp;lt;/syntaxhighlight&amp;gt; keyword, available for Build 139.32394 and later.  See [[#Examples Using ClassList|Examples - using ClassList]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(ClassArray,SubroutineName())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|For Example:&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot; inline&amp;gt;ForEachClass(Tanks, Init())&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* {{Available139|30094}}&lt;br /&gt;
* Used to loop through all instances in the specified Array of classes. &lt;br /&gt;
* In the above example, the function Init() will be called by the class instance array &amp;quot;Tanks&amp;quot;.  (Equivalent to calling, Tank[0].init(), Tank[1].init(), etc.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Sub can have any number of parameters, however string parameters are not supported. Where multiple class names (class types) are used, they must all have the same sub with the same parameters. Available for Build 139.31388 and later. Some examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pgm&amp;quot;&amp;gt;ForEachClass({T1,T5}, SetCalcOptions(true))&lt;br /&gt;
ForEachClass({T2,T3,T4}, SetCalcOptions(false))&lt;br /&gt;
ForEachClass(TankClass, UpdateResults(EnvironmentTemperature))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
*The Class instances or Array must be in the &#039;&#039;&#039;global scope&#039;&#039;&#039; and declared before &#039;&#039;&#039;ForEachClass&#039;&#039;&#039; is called.&lt;br /&gt;
*ForEachClass is not a true function, it is a convenient &#039;&#039;&#039;Macro&#039;&#039;&#039; that generates a sequence of code at PGM load time. This is why the location of ForEachClass is important relative to declaration of class instances (because it only uses the classes already declared when encountering ForEachClass during load).&lt;br /&gt;
*Use &#039;&#039;&#039;ExcludeClass&#039;&#039;&#039; to block classes from being used with the ForEachClass macro function. For example for an Array of classes use &amp;quot;ExcludeClass Tanks[0]&amp;quot; alongside &amp;quot;ExcludeWatch Tank[0]&amp;quot; to skip the first class instance in the array with any use of ForEachClass. {{Available139|31388}}&lt;br /&gt;
*A class instance within a class is excluded.&lt;/div&gt;</summary>
		<author><name>Eleanor.McFeaters</name></author>
	</entry>
</feed>