Tinderbox Icon

var


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Altered: 

 Property   [other Property operators]

 Item   [operators of similar scope]

 Data manipulation   [other Data manipulation operators]

 5.10.0

 format"


var()

Occasionally, an action may find it convenient to declare a local variable in which to save intermediate results. In the past, the only choice was to use a user attribute.

The var() statement declares a local variable:

var x;

var y(5)

var z("this is note "+$Name)

A local variable acts in most ways like a user attribute. Local variables exist for the duration of the action or, when they are declared inside curly brackets { … } their scope is the rest of the clause - i.e the remaining individual statements within the {}.

Local variables must be declared before use. If not explicitly initialised, their initial value is the empty string "".

Example:

$MyNum = 0; var x; x = 2; $MyNum = x; 

$MyNum is now 2. Now:

$MyNum = 0; {var x; x = 2; $MyNum = x; x=6;};$MyNum = x; 

$MyNum is now 0 (nothing) as 'x' has no meaning outside the (). But be careful. assume for a moment you have an actual attribute $x, then:

$MyNum = 0; {var x; x = 2; $MyNum = x; x=6;}; x = 4; $MyNum = x; 

$MyNum is 4 as the x=4 is read as the deprecated syntax of $x=4. So, be careful that a local variable's names doesn't match existing attributes. Remember the local variable does not take a $ prefix. It is a value reference - but not to an attribute.


Possible relevant notes (via "Similar Notes" feature):

Previous: values(attribute)  Next: word(data) 


A Tinderbox Reference File : Actions & Rules : Operators : Full Operator List : var aTbRef Site Map