VBScript Reference.pdf

(3830 KB) Pobierz
VBScript Reference Manual
for InduSoft Web Studio
www.InduSoft.com
info@indusoft.com
828049434.003.png
VBScript Reference Manual
InduSoft Web Studio
Copyright © 2006-2007 by InduSoft ® . All rights reserved worldwide.
No part of this publication may be reproduced or transmitted in any form or by any means without written authorization from InduSoft.
InduSoft is a registered trademark of InduSoft. CEView is a trademark of InduSoft.
The information contained within this document is subject to change without notice. InduSoft does not assume responsibility for any errors or
inaccuracies that may occur in this publication.
Visual Basic and VBScript are registered trademarks of Microsoft Corporation in the United States and other countries.
Other brand or product names are trademarks or registered trademarks of their respective owners.
Last updated: 09 April 2007
2
InduSoft, Ltd.
828049434.004.png
 
InduSoft Web Studio
VBScript Reference Manual
Table of Contents
About VBScript ......................................................................................................................................5
VBScript Limitations in IWS ..................................................................................................................7
The Microsoft Visual Basic Family.........................................................................................................8
Differences between VBScript and VBA ................................................................................................9
VBScript Hosting Environments...........................................................................................................10
VBScript Language Overview ..............................................................................................................11
VBScript Functionality .....................................................................................................................11
VBScript Elements ...........................................................................................................................11
Variable Data Types and Subtypes....................................................................................................12
Data Subtype Identification...............................................................................................................12
Data Subtype Conversion..................................................................................................................12
Variable Naming Rules & Conventions.............................................................................................13
Variable Scope..................................................................................................................................13
VBScript Constants...........................................................................................................................13
Declaring VBScript Variables and Constants ....................................................................................14
VBScript Keywords ..........................................................................................................................14
Operators ..........................................................................................................................................14
Operator Precedence .........................................................................................................................15
Functions ..........................................................................................................................................15
Statements ........................................................................................................................................18
Objects and Classes ..............................................................................................................................21
VBScript Object Commands .............................................................................................................23
VBScript User-Defined Class Objects...............................................................................................24
VBScript Objects and Collections .....................................................................................................28
Err Object .....................................................................................................................................29
Scripting Dictionary Object...........................................................................................................30
Scripting FileSystemObject...........................................................................................................31
COM Objects and Collections...........................................................................................................39
VBScript Configuration and Operation in IWS .....................................................................................43
Global Procedures.............................................................................................................................45
Graphics Script .................................................................................................................................46
Screen Scripts ...................................................................................................................................47
Command Dynamic ..........................................................................................................................49
ActiveX Events.................................................................................................................................50
Background Task Startup Script........................................................................................................51
Background Task Script Groups ........................................................................................................51
Scope of VBScript Procedures and Variables ....................................................................................53
Accessing IWS Tags and IWS Built-in functions ..............................................................................55
Accessing ActiveX Objects from VBScript .......................................................................................58
IntelliSense .......................................................................................................................................60
VBScript with Web Thin Clients.......................................................................................................62
VBScript Language Reference..............................................................................................................63
VBScript Variables ...........................................................................................................................64
Variable Data Types and Subtypes ................................................................................................64
InduSoft, Ltd.
3
828049434.005.png
 
VBScript Reference Manual
InduSoft Web Studio
Array Variables.............................................................................................................................66
Boolean Variables .........................................................................................................................67
Byte, Integer & Long Variables.....................................................................................................69
Currency Variables .......................................................................................................................69
Date (and Time) Variables ............................................................................................................70
Empty Variables ...........................................................................................................................72
Error Variables..............................................................................................................................72
Null Variables...............................................................................................................................72
Object Variables ...........................................................................................................................73
Real (Single, Double) Variables ....................................................................................................73
Strings Variables..........................................................................................................................74
Data Subtype Identification...........................................................................................................76
Data Subtype Conversion..............................................................................................................79
VBScript Naming Rules and Conventions.....................................................................................80
Variable Scope..............................................................................................................................82
VBScript Constants...........................................................................................................................84
Explicit Constants .........................................................................................................................84
Implicit Constants .........................................................................................................................86
Declaring Variables, Objects and Constants ..................................................................................95
VBScript Keywords ..........................................................................................................................97
VBScript Literals ..........................................................................................................................97
VBScript Operators...........................................................................................................................98
Arithmetic Operators.....................................................................................................................98
Assignment Operator ....................................................................................................................98
Comparison Operators ..................................................................................................................98
String Concatenation Operators.....................................................................................................98
Logical Operators..........................................................................................................................99
Is Operator ....................................................................................................................................99
$ Operator.....................................................................................................................................99
Operator Precedence ...................................................................................................................111
VBScript Functions.........................................................................................................................112
VBScript Derived Functions ...........................................................................................................169
VBScript Statements.......................................................................................................................170
VBScript Objects and Collections ...................................................................................................196
Scripting Type Library....................................................................................................................212
FileSystemObject (FSO) .................................................................................................................216
TextStream Object ..........................................................................................................................250
4
InduSoft, Ltd.
828049434.001.png
 
InduSoft Web Studio
VBScript Reference Manual
About VBScript
Visual Basic Script Language (VBScript) is one of Microsoft’s scripting languages that is commonly
associated with Server-side and Client-side web applications. However, Microsoft has opened up
VBScript to developers and now VBScript can be found in a variety of applications. InduSoft has
standardized on VBScript since it provides a significant subset of Microsoft Visual Basic’s functionality,
and VBScript supports all of Microsoft’s operating system platforms including Windows CE, unlike VBA
(Visual Basic for Applications) which cannot support the Windows CE runtime environment.
VBScript is a programming language that is often viewed as a dialect of VBA (Visual Basic for
Applications), although it is really its own language. The VBScript language attempts to balance
flexibility, capability and ease of use. VBA is a subset of Visual Basic that was developed to automate
Microsoft Office applications, whereas VBScript was originally developed to support Server-side and
Client-side web applications. Although VBScript and VBA provide many of the same features, there are
some differences between them, primarily due to the applications they were each developed to support.
So before we get into details of the VBScripting language, perhaps it is worthwhile to review how
VBScript is used with InduSoft Web Studio (IWS) or alternatively, why VBScript is included with IWS.
IWS provides an easy-to-use development environment that configures predefined objects to support
an HMI/SCADA application. Applications can be built quickly and are relatively easy to support, even by
someone other than the original developer. By comparison, programming languages such as Visual
Basic can be used to develop an HMI/SCADA application, but the lower per-copy licensing cost savings
quickly gets offset by much higher development costs and support costs. A programming development
environment is clearly more flexible than a configuration development environment, but there is a
significant cost associated with programming that makes it an unattractive alternative for HMI/SCADA
applications. By adding VBScript support to IWS, InduSoft lets you chose between configuration and
programming to meet your application needs and develop applications efficiently.
Using VBScript With InduSoft HMI/SCADA Applications
InduSoft Web Studio (IWS) supports both a simple, proprietary scripting language (worksheet style) using one
or more Math worksheets, as well as VBScript (new with IWS Version 6.1). Developers can use either
scripting language or a combination of both. VBScript code is placed in one of several modules, based on the
functionality to be performed and the scope of the code and its variables. This subject is covered more
completely in the VBScript Configuration and Operation in IWS section.
Examples of how VBScript can be used:
To execute a logic sequence or a routine when opening or closing a screen, or while the screen is open
To execute a logic sequence in the background
Run a simple VBScipt code segment based on an IWS object’s command dynamic
Interaction with IWS Tags and control of IWS built-in functions
Manipulation of ActiveX Controls and ActiveX Control event handler
Simple file I/O (e.g. text files)
Database interfaces (e.g. via ADO.NET), especially where use of SQL is required
Interface to Windows Management Instrumentation (WMI) and Web Services (via WSDL)
Interface to Microsoft Office applications (e.g. Excel, Access, Word) and Microsoft Office components
via OLE Automation
Run on a Web Thin Client
Where you should use IWS instead of VBScript
User Interface. IWS does not support Windows Scripting, which typically provides the User Interface for
VBScript via Forms.
Device I/O (e.g. PLC communications). VBScript does not directly support serial or network
communications.
InduSoft, Ltd.
5
828049434.002.png
 
Zgłoś jeśli naruszono regulamin