Navigation: Interface Design Concepts >

Variables

 

 

 

 

Variables are of the Variant type - That is they can act as string or numeric variables. It is recommended to prefix the name with var so that properties are not mistakenly used in code, such for a width use varWidth.

 

Variables are created with (and will be assigned 0):

!makeVar varName

 

Variables can be declared and initialized with:
!makeVar varName=50

 

Variables and their current values ARE saved when an interface is saved. When opened, the variables will be created initialized with their last values. If !makeVar name=value is issued by your code, it will update the value of the loaded variable. If you need to initialize a variable when the interface loads, it is recommended to use the <load> event property to create and initialize the variable.

!makeVar varWidth=20;

 

Variables are read like all properties and values and are global to the environment.
? The width is [varWidth]

 

 

Indexed variables

Indexed variables can be declared and used in code using the following:

!makeVarIndexed varName, maxIndex

 

The following will create the variables varLast0 to varLast9 and initialize them to 0.

!makeVarIndexed varLast, 10

 

When accessing them, some values such as the index property of a comboBox can be used as the index value. Say for example an item with an index of 3 is selected for cboChoice. The value of [cboChoice.index] would be returned as 3, replacing that text, leaving varLast3, which will be replaced by its value.

? [varLast[cboChoice.index]]

 

In a forLoop they can be indexed or displayed with:
!forLoop 0,9,1: ? varLast& = [varLast&]  // for 0 to 9 step 1, & holds count

 

Increment/Decrement Variables

Variables, including indexed ones, can be incremented and decremented with ++ and --, either post or pre use. The variable must hold a numeric value.
!makeVar varWidth=20

? [varWidth++]                      // Uses value then increments

? [++varWidth]                     // Increments then uses value

? [varWidth--]                      // Uses value then decrements

? [--varWidth]                     // Decrements then uses value

 

Reading from Controller

As with properties, the controller may read a variable via a !read request:

Serial.println("!read [varWidth]");

data = Serial.parseInt();

 

 

 

 

 

Copyright © 2024 SelmaWare Solutions, LLC