18.01.2013 Views

VBScript Reference Manual for InduSoft Web Studio

VBScript Reference Manual for InduSoft Web Studio

VBScript Reference Manual for InduSoft Web Studio

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>InduSoft</strong> <strong>Web</strong> <strong>Studio</strong> <strong>VBScript</strong> <strong>Reference</strong> <strong>Manual</strong><br />

This relationship between type Variant and the various data subtypes is explained by the fact that<br />

<strong>VBScript</strong> uses what is called “late-bound” typing, meaning that the data subtype is determined at<br />

runtime by its usage or by a function. At runtime, the Parser in the <strong>VBScript</strong> Scripting Engine will<br />

determine the data type required and allocate storage accordingly, then execute the statements or<br />

functions accordingly <strong>for</strong> the data type. Microsoft reportedly implemented <strong>VBScript</strong> with late-bound data<br />

typing in order to improve execution speed.<br />

In its simplest <strong>for</strong>m, a Variant contains either numeric or string data. A Variant behaves as a number<br />

when you use it in a numeric expression and as a string when you use it in a string expression. That is,<br />

if you are working with data that looks like numbers, <strong>VBScript</strong> assumes that it is a number and does<br />

what is most appropriate <strong>for</strong> numbers. Similarly, if you're working with data that can only be string data,<br />

<strong>VBScript</strong> treats it as string data. If you enclose a variable in quotation marks (" "), you will always make<br />

the variable behave as a strings. When variables are initialized, a numeric variable is initialized to 0 and<br />

a string variable is initialized to a zero-length string ("").<br />

A variable that refers to an object must be assigned to an existing object using the Set statement<br />

be<strong>for</strong>e it can be used. Until it is assigned an object, the declared object variable has the special value<br />

Nothing.<br />

Beyond simple numeric or string classifications, a Variant can be distinguished by the specific nature of<br />

data it contains or represents. For example, numeric in<strong>for</strong>mation can represent date or time. When the<br />

variable is used with other date or time variables or operations, the result is always expressed as a date<br />

or a time.<br />

The Variant type is best thought of as a super data type which includes all the data subtypes. You can<br />

change a variable’s value and subtype at runtime by assigning a new value to the variable from one<br />

previously assigned to it. For example:<br />

Dim x<br />

x = “message1” ‘ x would be a string subtype<br />

x = 1 ‘ x would now become a integer subtype<br />

Just to make this a little more confusing, if you had the statement<br />

x = 2.5<br />

this could be a Currency, Single or Double data subtype. By default, <strong>VBScript</strong> would consider 2.5 to be<br />

a Double data subtype. In the previous example, the variable x which was assigned a value of 1 could<br />

be a data subtype of Boolean, Byte, Integer or Long. <strong>VBScript</strong> by default would consider the variable x<br />

with a value of 1 to be an Integer data subtype.<br />

Key Notes:<br />

• The Dim keyword can be used to declare one or more variables. Multiple variables are<br />

separated by comma(s).<br />

• Option Explicit requires all variables to be declared, and is helpful to reduce typing<br />

(spelling) errors<br />

• The value assigned to a variable can be another variable, a named constant (implicit or<br />

explicit) or a literal. A literal is simply static data, and can be a string of text, number,<br />

date or a boolean value. E.g.<br />

a = 2<br />

myStr = “Alarm 1 on”<br />

<strong>InduSoft</strong>, Ltd. 65

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

Saved successfully!

Ooh no, something went wrong!