Paul McFedries' Web Home


VBA Unleashed cover Visual Basic for Applications Unleashed

Chapter 21—Web Page Programming: ActiveX and VBScript

Go To VBA Unleashed Home Page Go To Top Go To Prev Go To Next

The Differences Between VBA and VBScript

VBScript is designed as a strict subset of VBA. In other words, all elements of VBScript are present in VBA, but some VBA elements aren't implemented in VBScript. In almost all cases, these language constructs were left out of VBScript for one or both of the following reasons:

  • To make the scripts execute as quickly as possible: As you'll see, VBScript code is downloaded along with the rest of the HTML in a Web page, and the browser then interprets the script. Since in most cases the script exists to provide the user with a dynamic or interactive page, slow code interpretation would be counterproductive.
  • To provide extra security: Since scripts are small programs that execute on a remote machine without user intervention, some security must be provided. After all, few people would want to use a VBScript-enhanced page if there were a possibility that the code could disrupt or crash their machine. For this reason, all VBA language constructs that would give the script access to the user's hard drive or operating system have been expunged from VBScript.
Table 21.2 summarizes the VBA language features that aren't present in VBScript.

Table 21.2. VBA language elements that aren't implemented in VBScript.

VBA CategoryNot in VBScript

Arrays Arrays declared with lower bound <> 0
Array function
Option Base
Private, Public
Collection Add, Count, Item, Remove
Conditional Compilation #Const
#If...Then...#Else
Control Flow DoEvents
For Each...Next
With...End With
GoSub...Return, GoTo
On Error GoTo
On...GoSub, On...GoTo
Line numbers, line labels
Data Conversion CCur, CVar, CVDate
Format
Str, Val
Data Types All intrinsic data types except Variant
Type...End Type
Date/Time Date statement, Time statement
Timer
DDE LinkExecute, LinkPoke, LinkRequest, LinkSend
Debugging Debug.Print
End, Stop
Declaring Variables Declare
Public, Private, Static>BR> New
Const
Type-declaration characters
Error Handling Erl
Error
On Error...Resume
Resume, Resume Next
File I/O All
Financial Functions All
Object Manipulation CreateObject
GetObject
TypeOf
Objects Clipboard
Collection
Operators Like
Options Deftype
Option Base
Option Compare
Option Private Module
Strings Fixed-length strings
LSet, RSet
Mid statement
StrConv

NOTE: YOU CAN'T SET THE DATE AND TIME
VBScript doesn't implement the Date and Time statements because they can be used to set the system date and time. If you just need to know the current date and time on the user's system, you can use the Date and Time functions (as well as other date/time functions, such as Hour and Day).

Other than the restrictions outlined in Table 21.2, the rest of the VBA universe is at your disposal. You can use If...Then...Else statements, Do...Loop structures, functions such as MsgBox and Format, and whatever else your code requires.

Not only that, but there's also a special object hierarchy for scripts that exposes numerous browser objects. Therefore, by using the properties, methods, and events associated with these objects, you gain a tremendous amount of control over how a browser looks and acts.

Go To VBA Unleashed Home Page Go To Top Go To Prev Go To Next


Copyright © 1995-2008 Paul McFedries and Logophilia Limited