18.01.2015 Views

Technical Reference Manual - InduSoft

Technical Reference Manual - InduSoft

Technical Reference Manual - InduSoft

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Overview of VBScript<br />

Scope and Lifetime of Variables<br />

A variable's scope is determined by where you declare it. When you declare a variable within a procedure,<br />

only code within that procedure can access or change the value of that variable. It has local scope and is a<br />

procedure-level variable. If you declare a variable outside a procedure, you make it recognizable to all the<br />

procedures in your script. This is a script-level variable, and it has script-level scope.<br />

The lifetime of a variable depends on how long it exists. The lifetime of a script-level variable extends from<br />

the time it is declared until the time the script is finished running. At procedure level, a variable exists only<br />

as the procedure runs. When the procedure exits, the variable is destroyed. Local variables are ideal as<br />

temporary storage space when a procedure is executing. You can have local variables of the same name in<br />

several different procedures because each is recognized only by the procedure in which it is declared.<br />

Boolean Tags and Boolean Variables<br />

By default, Boolean variables in VBScript are handled differently than Boolean tags are handled in IWS. The<br />

Boolean states of FALSE and TRUE have the same meaning, but the numeric values of TRUE are different, as<br />

shown in the table below.<br />

Boolean State<br />

Numeric Value in…<br />

Project Tag<br />

VBScript Variable<br />

FALSE 0 0<br />

TRUE 1 −1<br />

Note: In VBScript, False and True are also reserved as keywords.<br />

This difference in how Booleans are handled can seriously affect runtime behavior if you use VBScript in<br />

your project. Logical and arithmetic operations — especially the NOT operator — could change tag values in<br />

unexpected ways.<br />

You can change this behavior, if necessary, by changing your project's runtime settings.<br />

Changing How VBScript Handles Boolean Tags<br />

You can change the way VBScript handles Boolean tags by activating "VB Boolean" mode. To do this, edit<br />

your project file (project_name.app) to change the following setting:<br />

[Script]<br />

VBBoolean=value<br />

If VBBoolean is set to 0, then the project will behave as described above: all VBScript functions and<br />

operations will read/write a value of −1 for TRUE to Boolean tags. This is the default setting for projects<br />

created with <strong>InduSoft</strong> Web Studio v6.1+SP3 or earlier and then updated to v6.1+SP4, in order to maintain<br />

backward compatibility.<br />

If VBBoolean is set to 1, then VBScript — as it is implemented within IWS — will read/write a value of 1<br />

for TRUE to Boolean tags. (This does not affect Integer or Real tags.) This is the default setting for projects<br />

created with <strong>InduSoft</strong> Web Studio v6.1+SP4 or later.<br />

Note: Be careful when defining a custom property on a Linked Symbol using the #Label:@Pointer<br />

syntax. For example:<br />

'The following statements are valid<br />

If $MyBoolean = 1 Then<br />

End If<br />

If $MyBoolean = True Then<br />

End If<br />

If #Mne:@MyPointer = True Then<br />

End If<br />

Page 788<br />

<strong>InduSoft</strong> Web Studio

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!