UIEvolutin Inc.
UJML Language Reference
Variables

Variables are named memory locations with a specified data type.

Note: If you are new to variables, see Variables Explained. 

A variable is a named area of device memory containing a value of a specified type. 

In UJML, a variable is declared using a var element inside of a variables element. See var, variables. Variables must have valid names and data types. See Identifiers, Data Types. Variable scope is determined by the element containing the variables element in which the variable is declared. See Data Scoping and Sharing.

Array Variables

Variables may be defined as arrays using the size attribute of the var element. See Arrays. Any one array element acts exactly the same as a simple variable of the same data type. Array variables may not be assigned to or passed as function arguments without specifying an array element.

Variable lifetime

Variables exist in memory for the lifetime of the application.

Variables inside of functions

Variables declared inside of a function element also exist for the lifetime of an application and are not re-entrant. See User Defined Functions.

Assigning values

Variables may be assigned the value of another variable, a literal, a function call result, or an expression of the proper data type. Until the variable is assigned an initial value, it has a default value, assigned when the variable was created.

Data Type 
Default Value 
boolean 
false 
reference 
null 
int 
string 
"" (Empty string) 
Assignment and type conversions

With the exception of the reference data type, you can always assign a literal, variable or expression of a similar data type to a variable. For variables of the reference data type, you can only assign a value returned by a component function, another reference variable, or the literal value null. See Components, Literals and Constants

In most cases, you cannot directly assign a variable or expression of one data type to a variable of a different data type, although UJML supports some data type conversions. The following table details what kinds of data conversions are possible. 

Note: For more examples of assignment and data conversion, see the assignment.ujml sample.

From 
To 
Description 
Example 
Result 
int 
boolean 
No direct assignment. You can use a boolean expression or conversion function. 
i = 128;
b = (i &_GT; 10); 
true 
string 
boolean 
No direct assignment. You can use a boolean expression or conversion function. 
s = "Foo";
b = (_streq(s, "Bar")); 
false 
boolean 
int 
No direct assignment. You can use an if statement. 
b = true;
if (b)
{
i = 1;
}
else
{
i = 0;
} 
1 
string 
int 
No direct assignment. You can use a conversion function or an if statement. 
s = "1024"
i = _string_to_int(s); 
1024 
boolean 
string 
Direct assignment is supported. 
b = true;
s = b; 
"true" 
int 
string 
Direct assignment is supported. 
i = 128;
s = i; 
"128" 
reference 
reference 
Direct assignment is supported, with automatic casting to the correct interface type (if the references are for different interface types). If the component instance being assigned does not implement the expected interface type, then null is assigned. See reference data type, Interface Types, Components, Interfaces
fooRef = barRef; 
fooRef now contains the 'foo' interface of the component instance in barRef
Topic 
Description 
This is a simplified explanation of variables. 

The following example shows how to declare a boolean variable. It is part of the assignment.ujml sample.

<var name="mBooleanVar" type="boolean"/>

 

The following example shows how to set the variable declared above to a boolean literal. It is part of the assignment.ujml sample.

mBooleanVar = true;

 

The following example shows how to set the variable declared above to the result of a boolean expression. It is part of the assignment.ujml sample.

mIntVar = 100;
mBooleanVar = (mIntVar &_GT; 99);

 

The following example shows how to declare an int variable. It is part of the assignment.ujml sample.

<var name="mIntVar" type="int"/>

 

The following example shows how to set the variable declared above to a numeric literal and then uses it in a mathematical expression. It is part of the assignment.ujml sample.

mIntVar = 512;
mIntVar = mIntVar * 2;

 

The following example shows how to declare a string variable. It is part of the assignment.ujml sample.

<var name="mStringVar" type="string"/>

 

The following example shows how to set the variable declared above to a string literal. Note that this is not a number because it is surrounded by double quotes. It is part of the assignment.ujml sample.

mStringVar = "-1024";

 

The following example shows how to declare a one-dimensional and a three-dimensional array. It is part of the assignment.ujml sample.

<var name="m3DArray" type="string" size="2, 3, 4"/>
<var name="mMessages" type="string" size="&MESSAGE_COUNT;"/>

 

The following example shows how to set a value for one element of the one-dimensional array declared above. It is part of the assignment.ujml sample.

mMessages[0] = "1: A simple string assignment.";

 

The following example shows how to set values for elements of the three-dimensional array declared above. It is part of the assignment.ujml sample.

// Fill a multidimensional array.
for (mCtr1 = 0; mCtr1 &_LT; 2; mCtr1++)
{
    for (mCtr2 = 0; mCtr2 &_LT; 3; mCtr2++)
    {
        for (mCtr3 = 0; mCtr3 &_LT; 4; mCtr3++)
        {
            m3DArray[mCtr1][mCtr2][mCtr3] = _strcat(mCtr1, "/", mCtr2, "/", mCtr3);
        }
    }
}

 

The following example shows how to declare a reference variable of a particular interface type. It is part of the life.ujml sample.

<var name="mGrid" type="ILifeGrid"/>

 

The following example shows how to assign a newly created component instance to the reference variable declared above. It is part of the life.ujml sample.

mGrid = _createInstance("LifeGrid");

 

The following example shows how to assign one reference variable to an element of an array of reference variables. It is part of the timer.ujml sample.

mListeners[mListenerCount] = listener;
Copyright (c) 2000-2007 UIEvolution, Inc. All rights reserved.
What do you think about this topic? Send feedback!