A clear description is given in MSDN
VBScript
VBScript is a subset of Visual Basic for Applications. Therefore,
VBScript programming has many similarities to Visual Basic for
Applications programming. Many of the powerful features of Visual Basic
for Applications, such as classes and API calls, were omitted to make
the language portable and secure.
Although VBScript is just text and can be written with a simple text
editor, a graphical design tool for VBScript is available. This visual
layout tool is called ActiveX Control Pad. ActiveX Control Pad
allows you to combine HTML code, ActiveX controls, HTML layouts, and
VBScript or JavaScript. ActiveX Control Pad works in conjunction with
the HTML Layout control. The HTML Layout control is a drawing board that
allows you to visually add and manipulate controls. ActiveX Control Pad
will be discussed in detail later in this book.
VBScript promises the same boom in ActiveX development that we have seen
in OCX controls development. Because VBScript, with the support of the
Internet Explorer, can automate ActiveX components, vendors can design
ActiveX controls to perform particular Internet tasks. A stock ticker
control is a good example of such a control. Admittedly, we already have
a rich assortment of ActiveX controls in the form of OCX controls, but
these controls are typically not optimized for downloading across the
Internet. For example, many of these controls contain sizable
design-time components that cause long delays during a download.
VBScript does not have an integrated debugging environment (IDE). This
means that code debugging can be rather demanding. Typically, you run
the script in a browser and troubleshoot any errors that may occur.
Perhaps the most useful debugging component is a well-placed MsgBox, and
until a complete IDE is available, development will remain cumbersome.
The obvious need for an IDE is overwhelming, and Microsoft certainly
knows that programmers want one; however, releasing VBScript "as is"
allows developers to get a handle on the new concepts without waiting
for a more formal product. After coding a few pages directly, you will
quickly master any IDE that is delivered in the future.
Compatibility with existing browsers is another issue for VBScript.
Although the Internet Explorer supports both VBScript and JavaScript,
VBScript is not currently supported by the Netscape browser. In the
future, we may see support from Netscape and others, but for now,
interactive web sites that use VBScript are limited to platforms running
the Internet Explorer.
In a bid to create standard scripting support that would broaden the
appeal of VBScript while maintaining current support for other engines,
such as JavaScript, Microsoft is working with the World Wide Web
Consortium to develop a standard for ActiveX Scripting and the
event-driven model. Such efforts will improve the viability of VBScript,
but even without an absolute standard, the Internet Explorer promises
to have a large market share because of tight integration with future
releases of Windows. Ultimately, VBScript may take center stage in
Windows development as the browser becomes the primary desktop
interface. Work is ongoing at Microsoft to completely unify the desktop
environment inside the browser, creating a single, comprehensive view of
local files, network files, and Internet files. This new view is known
as page view.
Implementing page view will radically alter the Windows desktop
environment. First and foremost, the concept of a separate browser
running on a desktop is eliminated. In fact, the browser will be
the desktop. Imagine an environment in which the Windows Explorer is
replaced by a browser interface. You will view all of the files on your
local machine just as if they are web pages. Need to see a Word
document? View it in a browser. Need to work on a Microsoft Excel
spreadsheet? Open it in the browser.
Ultimately, the user will work with all data the same way, regardless of
the location of the data. For example, local, network, and Internet
files will be seamlessly integrated into the browser interface. This
represents a significant advance in the user interface because users
will no longer have to worry about data location and the technical
knowledge necessary to connect to the data.
JavaScript Versus VBScript
JavaScript and VBScript have many similarities. In fact, anyone who has
mastered VBScript will find JavaScript just as easy to learn. Since the
Internet Explorer supports both languages, knowledge of the fundamentals
of both is valuable. The key differences between JavaScript and
VBScript are covered in the paragraphs that follow.
Syntax
As stated before, the most obvious difference is syntax. JavaScript uses
curly braces to denote functions, whereas VBScript uses Function…End
Function and Sub…End Sub. In fact, JavaScript supports only functions,
whereas VBScript supports functions and subroutines. If you want to
create a function that behaves like a subroutine in JavaScript, simply
omit the return value.
Objects
Neither JavaScript nor VBScript is truly object-oriented. Without
digressing into a full definition of object-oriented programming, we can
safely say that neither language exhibits all of the characteristics of
a truly object-oriented language. Neither language, for example,
supports the concept of inheritance.
JavaScript, however, makes stronger use of objects than does VBScript.
JavaScript allows for the definition of classes for the subsequent
creation of objects. To define a class, you create a function that
specifies the class name and the class's properties and methods. For
example, the following code defines a class called Student that has three properties:
function Student (name, height, weight) {
this.name=name
this.height=height
this.weight=weight
}
Values are assigned to properties using the this keyword, which
always references the new object. This type of design allows JavaScript
to encapsulate properties and methods inside an object. Creating an
instance of the Student class is a simple matter of calling the function
and using the new keyword:
mystudent=new Student("John",70,175)
Unfortunately, VBScript does not support object creation or user-defined
classes. VBScript supports only reusable functions and subroutines. In
order to use VBScript to manage the above information for multiple
students, we would have to create separate variables for each student we
wanted to track. We could accomplish this by using arrays, for example.
Language Scalability
A primary difference between VBScript and JavaScript is scalability.
Once you learn VBScript, you are well on your way to learning Visual
Basic for Applications. If you know Visual Basic or Visual Basic for
Applications, you know VBScript. Although JavaScript has similarities to
C++, it is a new language.
Other Scripting Languages
Because Microsoft has designed ActiveX Scripting to be an open standard,
JavaScript and VBScript may soon be joined by other scripting
languages. The Internet Explorer can support any scripting language that
takes advantage of ActiveX Scripting. Third-party vendors may choose to
design their own scripting languages.
The VBScript Language
In order to understand the VBScript language, you must first understand
what's missing. VBScript is not a complete, mature development language.
Many features that are a necessity in advanced languages, such as data
types, are not supported in VBScript. The language is a simple
collection of fundamental features taken right out of the Visual Basic
for Applications language. If you have programmed with Visual Basic for
Applications before, you will find VBScript familiar. Table 2-1 shows
the features of the VBScript language. Appendix C shows the Visual Basic
for Applications features that are not supported by VBScript. For more
information, consult the VBScript documentation on this book's companion
CD and at Microsoft's web site.
Table 2-1.The VBScript Language
| Category |
Keywords |
| Array handling |
Array function
Declaration (Dim, Static, etc.)
Lbound, Ubound
ReDim, Erase
|
| Assignment |
=, Let, Set |
| Comments |
REM and ' |
| Constants/Literals |
Empty, Nothing, Null
True, False
User-defined literals
|
| Control flow |
Do…Loop
For…Next, For Each...Next
While…Wend
If…Then…Else
Select…Case
|
| Conversion |
Abs
Asc, Chr
CBool, CByte
CDate, CDbl, CInt
CLng, CSng, CStr
CVErr
Fix, Int, Sgn
Hex, Oct
|
| Date/Time |
Date function, Time function
Day, Month, Weekday, Year
Hour, Minute, Second
Now
DateSerial, DateValue
TimeSerial, TimeValue
|
| Error handling |
On Error Resume Next
Err Object
|
| Input/Output |
InputBox
MsgBox
|
| Math |
Atn, Cos, Sin, Tan
Exp, Log, Sqr
Randomize, Rnd
|
| Miscellaneous |
Line continuation character (_)
Line separation character (:)
|
| Objects |
Create Object |
| Operators |
+, -, *, /, ^, Mod
Integer Division (\)
Negation (-)
String concatenation (&)
=, <>, <, >, <=, >=, Is
Not, And, Or, Xor
Eqv, Imp
|
| Options |
Option Explicit |
| Procedures |
Function, Sub
Exit Function, Exit Sub
Call
ByVal, ByRef
|
| Strings |
Asc, AscB, AscW
Chr, ChrB, ChrW
Instr, InStrB
Len, LenB
LCase, UCase
Left, LeftB
Mid, MidB
Right, RightB
Space(number)
StrComp
String(number, character)
Trim, LTrim, RTrim
|
| Variables |
Procedure-level:
Dim, Static
Module-level:
Private, Dim
|
| Variants |
IsArray
IsDate, IsEmpty, IsError
IsNull, IsNumeric, IsObject
VarType
|