omron — Boolean Tags and Boolean Variables

Appendix: VBScript a "vb" or "con" prefix on your constant names, or you might name your constants in all capital letters. Differentiating constants from variables eliminates confusion as you develop more complex scripts. Declaring Variables A variable is a convenient placeholder that refers to a computer memory location where you can store program information that may change during the time your script is running. In VBScript, variables are always of one fundamental data type, Variant. You declare variables explicitly in your script using the Dim statement, the Public statement, and the Private statement. For example:

Dim DegreesFahrenheit You declare multiple variables by separating each variable name with a comma. For example: Dim Top, Bottom, Left, Right You can also declare a variable implicitly by simply using its name in your script. That is not generally a good practice because you could misspell the variable name in one or more places, causing unexpected results when your script is run. For that reason, the Option Explicit statement is configured by default in the Global Procedures interface to require explicit declaration of all variables.

Unless you delete this statement, you need to declare all variables explicitly; otherwise, VBScript will generate errors during runtime indicating that the variable does not exist. An expression should have the variable on the left side and the value you want to assign to the variable on the right. For example: MyVar = 100 Scope and Lifetime of Variables A variable's scope is determined by where you declare it. When you declare a variable within a procedure, only code within that procedure can access or change the value of that variable. It has local scope and is a procedure-level variable.

If you declare a variable outside a procedure, you make it recognizable to all the procedures in your script. This is a script-level variable, and it has script-level scope. The lifetime of a variable depends on how long it exists. The lifetime of a script-level variable extends from the time it is declared until the time the script is finished running. At procedure level, a variable exists only as the procedure runs. When the procedure exits, the variable is destroyed. Local variables are ideal as temporary storage space when a procedure is executing.

You can have local variables of the same name in several different procedures because each is recognized only by the procedure in which it is declared. Boolean Tags and Boolean Variables By default, Boolean variables in VBScript are handled differently than Boolean tags are handled in IWS. The Boolean states of FALSE and TRUE have the same meaning, but the numeric values of TRUE are different, as shown in the table below. Note: In VBScript, False and True are also reserved as keywords . This difference in how Booleans are handled can seriously affect runtime behavior if you use VBScript in your project.

Logical and arithmetic operations — especially the NOT operator — could change tag values in unexpected ways. You can change this behavior, if necessary, by changing your project's runtime settings. Changing How VBScript Handles Boolean Tags You can change the way VBScript handles Boolean tags by activating "VB Boolean" mode. To do this, edit your project file ( project_name .app ) to change the following setting: [Script] VBBoolean= value InduSoft Web Studio Page 667 Boolean State Numeric Value in… Project Tag VBScript Variable FALSE 0 0 TRUE 1 −1