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 />

<strong>VBScript</strong> Variables<br />

Variable Data Types and Subtypes<br />

VB and VBA are compiled languages that require you to explicitly declare the variables you are going to<br />

use and their data type. To explicitly declare a VB or VBA variable, you would use the Dim keyword.<br />

The following example shows how VB or VBA would declare the variable x as an integer:<br />

Dim x As Integer<br />

Dim a, b, c As Integer<br />

With <strong>VBScript</strong>, you also use the Dim statement to explicitly declare a variable. However, you are not<br />

required to explicitly declare variables in <strong>VBScript</strong>. If you do not explicitly declare a variable, it is<br />

implicitly declared when the variable is used. However, typing (spelling) errors can typically go<br />

undetected until a problem occurs, and then must be detected and corrected. By adding the Option<br />

Explicit command at the beginning of the script, you can <strong>for</strong>ce the <strong>VBScript</strong> Scripting Engine to only<br />

use the variables that are explicitly declared.<br />

Example Dim a, b ‘ explicitly declares the variables a & b<br />

a = 4 ‘ assigns the value of 4 to variable a<br />

b = 4 ‘ assigns the value of 4 to variable b<br />

c = a + b ‘ <strong>VBScript</strong> will create a variable c, and then per<strong>for</strong>m the<br />

add<br />

Example Option Explicit ‘ Force explicit definition of variables<br />

Dim a, b ‘ declare variables a and b<br />

a = 4 ‘ define variable a<br />

b = 4 ‘ define variable b<br />

c = a + b ‘ will generate an error since c not explicitly declared<br />

Interestingly, <strong>VBScript</strong> does not allow you declare the variable data type (i.e. integer, real, etc.) in the<br />

Dim statement. In fact, <strong>VBScript</strong> does not support data Type declarations. This is a major difference<br />

between <strong>VBScript</strong> and VB/VBA. Instead, all <strong>VBScript</strong> variables are of a data type called Variant,<br />

meaning the data type can be whatever is required. However, there are a variety of <strong>VBScript</strong> Variant<br />

data subtypes that correspond to traditional data types familiar to programmers. These variant data<br />

subtypes are:<br />

Variant data subtypes<br />

Subtype Description<br />

Array An indexed list of variants<br />

Boolean Boolean value of either True or False. False has a value of 0, and True has a value of -1.<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. Note that this is not the object itself.<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 />

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

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

Saved successfully!

Ooh no, something went wrong!