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>VBScript</strong> <strong>Reference</strong> <strong>Manual</strong> <strong>InduSoft</strong> <strong>Web</strong> <strong>Studio</strong><br />

Variable Data Types and Subtypes<br />

All variables in <strong>VBScript</strong> are a data type called Variant. This means that you do not (and cannot)<br />

explicitly declare the variable type. In fact, with <strong>VBScript</strong> you do not need the Dim statement to allocate<br />

storage <strong>for</strong> a variable. At runtime, the Parser in the <strong>VBScript</strong> Scripting Engine determines the Variant<br />

data subtype to be used. These correspond to the more traditional classifications of data types (see<br />

chart below).<br />

Variant data subtypes<br />

Subtype Description<br />

Boolean Either True or False<br />

Byte Contains integer in the range 0 to 255<br />

Currency Floating-point number in the range -922,337,203,685,477.5808 to 922,337,203,685,477.5807<br />

Date(Time) Contains a number that represents a date between January 1, 100 to December 31, 9999<br />

Double Contains a double-precision, floating-point number in the range -1.79769313486232E308 to -<br />

4.94065645841247E-324 <strong>for</strong> negative values; 4.94065645841247E-324 to<br />

1.79769313486232E308 <strong>for</strong> positive values<br />

Empty Uninitialized Variant<br />

Error Contains an error number used with runtime errors<br />

Integer Contains integer in the range -32,768 to 32,767<br />

Long Contains integer in the range -2,147,483,648 to 2,147,483,647<br />

Null A variant containing no valid data<br />

Object Contains an object reference<br />

Single Contains a single-precision, floating-point number in the range -3.402823E38 to -1.401298E-45<br />

<strong>for</strong> negative values; 1.401298E-45 to 3.402823E38 <strong>for</strong> positive values<br />

String Contains a variable-length string that can be up to approximately 2 billion characters in length.<br />

The Parsers choice of data subtype will depend on how the variable is used in a statement or function.<br />

Note that a variable’s subtype can change within a code segment.<br />

Data Subtype Identification<br />

If it is important to determine the Variant data subtype used at runtime, you may use any of the three<br />

categories of functions to determine the data subtype:<br />

• The VarType(variable) function which returns a code based on the Variant data subtype used<br />

• Various IsXxxx(variable) functions which return boolean values indicating whether the variable<br />

is of a specific data subtype.<br />

• A TypeName(variable) function which returns a string based indicating the data subtype<br />

Example: If varType(a) = vbInteger Then<br />

Msgbox “a is an Integer”<br />

EndIf<br />

Data Subtype Conversion<br />

<strong>VBScript</strong> provides several functions that convert a variable from one data subtype to another. Since<br />

<strong>VBScript</strong> uses the Variant data type, these functions are not generally required. However, when<br />

passing data between IWS (or CEView) and <strong>VBScript</strong>, or calling built-in IWS functions from <strong>VBScript</strong><br />

where variables need to be put into the proper argument <strong>for</strong>mat, these <strong>VBScript</strong> data subtype<br />

conversion functions can be very useful.<br />

Example: a = 4.2<br />

b = cInt (a) ‘ b is an Integer with a value of 4<br />

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

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

Saved successfully!

Ooh no, something went wrong!