var

Tinderbox Icon


Operator Type:   Property
Operator Scope of Action:   Item
Operator Purpose:   Data manipulation

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.

In v5.10.0 the new 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):

Up: Item-based operators

A Tinderbox Reference File : Actions & Rules : Operators : Action Operator Scope : Item-based operators : var

Quicklinks: Attributes | Action Codes | Export Codes | Designators | Date Formats | aTbRef Site Map

[Last updated: 16 May 2012, using v5.11.1]


Search:

Google search aTbRef for:  


Creative Commons Licence

aTbRef by Mark Anderson is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

[See aTbRef CC licence Attribution & Waiver info]

Made with Tinderbox