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

Object Variables<br />

The Object data subtype references an object. Although the topic of objects will be covered in detail<br />

later, at this point it is worth noting that there are two types of Objects; Intrinsic (i.e. <strong>VBScript</strong>-based)<br />

and Extrinsic Objects.<br />

Intrinsic Objects are pre-defined by <strong>VBScript</strong>. <strong>VBScript</strong> includes the intrinsic Err object <strong>for</strong> error<br />

handling. The programmer can only use the Err object name <strong>for</strong> this object.<br />

Extrinsic objects need to be declared, or instantiated (i.e. create an instance of the Object). With<br />

extrinsic objects, the programmer defines an object name in the declaration statement. The object<br />

name can be any valid variable name allowed by <strong>VBScript</strong>, although following variable naming<br />

conventions is strongly suggested.<br />

Depending on the type of extrinsic object, different statements are used to instantiate the object. For<br />

example, with user-defined Classes, you would use the following <strong>for</strong>mat to instantiate the object.<br />

Set cObj = New classname<br />

where cObj is the name of the new object being instantiated, New is a <strong>VBScript</strong> Keyword, and<br />

classname is the name of the user-defined class, which is merely a template <strong>for</strong> the object.<br />

Other extrinsic objects include ActiveX Objects, ADO.NET, and OLE Automation Objects such as<br />

Microsoft Office applications and components. These objects use a different statement <strong>for</strong>mat <strong>for</strong><br />

instantiation. They use either the CreateObject or GetObject functions. For example:<br />

Set cObj = CreateObject(“ADODB.Connection”)<br />

Set xlObj = CreateObject(“Excel.Application”)<br />

Set xlBook = GetObject(“C:\Test.XLS”)<br />

The difference between CreateObject and GetObject is that CreateObject is used to create an interface<br />

to a new instance of an application (or object) while the GetObject is used with an application that is<br />

already loaded.<br />

Real (Single, Double) Variables<br />

Real data types in <strong>VBScript</strong> are floating point numbers that can be either single precision (Single) or<br />

double precision (Double). Their ranges are:<br />

Single -3.402823E+38 to -1.401298E-45 <strong>for</strong> negative values<br />

1.401298E-45 to 3.402823E+38 <strong>for</strong> positive values<br />

Double -1.79769313486232E+308 to -4.94065645841247E-324 <strong>for</strong> negative values<br />

4.94065645841247E-324 to 1.79769313486232E+308 <strong>for</strong> positive values<br />

There are several types of operations that can be per<strong>for</strong>med on the Real data subtype, such as<br />

arithmetic, comparison and logical operators. Also, many math functions can be used with this data<br />

subtypes. Some examples are:<br />

Dim R1, R2, R3, Radius<br />

R1 = 3.14159<br />

Radius = 2<br />

R2 = R1 * radius * radius<br />

R3 = FormatNumber (R2, 2) ‘ R3 equals 12.57 (R2 = 12.56636)<br />

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

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

Saved successfully!

Ooh no, something went wrong!