Learn how to create and use variables in the FlexiLayout language code sections
You can create and use variables in any section where code is entered. The name of a variable cannot coincide with the name of a global constant or the name of an element.Variables can be created in one of two ways.
Declare a Variable by Specifying Its Type and Name
The syntax is as follows:
Copy
Ask AI
[type name] [variable name];
For example:
Copy
Ask AI
Int a;
Copy
Ask AI
String s;
Copy
Ask AI
Logic isElementLongEnough;
To call the value of a variable, you must first initialize it by using an assignment operator. Calling a variable that has not been initialized will result in an error during compilation or when executing the code.
Declare a Variable and Initialize It at the Same Time
You can declare and initialize a variable using an expression, e.g. an element name, an element property or another variable. The syntax is as follows:
Copy
Ask AI
Let [variable name] = [expression]
For example:
Copy
Ask AI
Int a;a=3; Let a1 = a + 5;
Copy
Ask AI
Let myElement = SearchObjects.Group1.Group2.FirstItem
Copy
Ask AI
Let myRect = SearchObjects.Group1.Group2.FirstItem.Rect
The system creates a variable with the specified name. The type of the variable is implicitly defined by the type of the expression it refers to. At the same time the variable is initialized using the value of the expression.Variables created using this method can be conveniently used as shortcut names for deeply nested elements and other objects to make the notation shorter.