Special Edition Using HTML 4

Previous chapterNext chapterContents


- C -
JavaScript Keyword Reference

by Rick Darnell

Key Differences Between VB and VBScript

You didn't run out to the computer store and buy a copy of VBScript. You didn't install a VBScript disk on your computer, either. All you did was install the Internet Explorer browser, which supports VBScript, on your computer--just like millions of other folks. Everyone of them has the VBScript engine on their computer, and everyone of them has the ability to create Web pages with VBScript.

So where's the integrated development environment that you're used to using in Visual Basic? Keep looking, because there isn't one. All you have is your favorite text editor, the ActiveX Control Pad, and a Web browser. That in itself is the single largest difference between Visual Basic and VBScript. It leads to some specific differences, too. Here's what they are:

You don't compile a VBScript program into an EXE file like you do with a Visual Basic program. You distribute your scripts as plain, old text embedded in HTML files. Everyone and his uncle can read your scripts. The script engine interprets this text into intermediate code when it loads the Web page. It also creates a symbol table so that it can quickly look up things such as event-procedures and variable names. The scripting engine uses the ActiveX Scripting technology to interact with the browser.


[BEG]NOTE:[END] You'll find a plethora of nit-picky differences between Visual Basic and VBScript, too. You have to use the value property to query an objects value, for example. Thus, instead of reading a text box's value using form.text, you have to read it using form.text.value. These subtle differences are too numerous to document in this appendix. Go to Microsoft's Web site (www.microsoft.com) and their knowledge base for further explanation of these differences.

Another significant difference between Visual Basic and VBScript is the keywords that Microsoft omitted from VBScript. You'll learn more about the keywords included in VBScript in the next section. You'll learn about the keywords that Microsoft omitted from VBScript in "Visual Basic Keywords Omitted from VBScript," later in this appendix.

Visual Basic Keywords Included in VBScript

VBScript includes all the keywords and features that you need to activate a Web page. You can't read or write files, as you'll learn later in this appendix, but you can handle any event that an object fires. You can also handle just about any type of data that you'll find on a Web page and manipulate the Web page in anyway you want.

Table C.1 describes each keyword or feature available in VBScript. I've divided this table into broad categories, with each entry under a category describing a single feature. I've used the same categories that Microsoft uses so that you can keep this information straight as you bounce back and forth between Microsoft's Web site and this book. If you don't find a feature that you expect to see, check out Table C.2 to see if that feature is in the list of Visual Basic features omitted from VBScript.

You can find more information about VBScript's features at Microsoft's VBScript Web site: http://www.microsoft.com/vbscript.

Table C.1  VBScript Keywords

Keyword/Feature Description
Array handling
IsArray Returns True if a variable is an array
Erase Reinitilizes a fixed-size array
LBound Returns the lower bound of an array
UBound Returns the upper bound of an array
Assignments
= Assigns a value to a variable
Let Assigns a value to a variable
Set Assigns an object to a variable
Comments
` Includes inline comments in your script
Rem Includes comments in your script
Constants/Literals
Empty Indicates an uninitialized variable
Nothing Disassociates a variable with an object
Null Indicates a variable with no data
True Boolean True
False Boolean False
Control flow
Do...Loop Repeats a block of statements
For...Next Repeats a block of statements
For Each...Next Repeats a block of statements
If...Then...Else Conditionally executes statements
Select Case Conditionally executes statements
While...Wend Repeats a block of statements
Conversions
Abs Returns absolute value of a number
Asc Returns the ASCII code of a character
AscB Returns the ASCII code of a character
AscW Returns the ASCII code of a character
Chr Returns a character from an ASCII code
ChrB Returns a character from an ASCII code
ChrW Returns a character from an ASCII code
CBool Converts a variant to a boolean
CByte Converts a variant to a byte
CDate Converts a variant to a date
CDbl Converts a variant to a double
Cint Converts a variant to an integer
CLng Converts a variant to a long
CSng Converts a variant to a single
CStr Converts a variant to a string
DateSerial Converts a variant to a date
DateValue Converts a variant to a date
Hex Converts a variant to a hex string
Oct Converts a variant to an octal string
Fix Converts a variant to a fixed string
Int Converts a variant to an integer string
Sgn Converts a variant to a single string
TimeSerial Converts a variant to a time
TimeValue Converts a variant to a time
Dates/Times
Date Returns the current date
Time Returns the current time
DateSerial Returns a date from its parts
DateValue Returns a date from its value
Day Returns day from a date
Month Returns month from a date
Weekday Returns weekday from a date
Year Returns year from a date
Hour Returns hour from a time
Minute Returns minute from a time
Second Returns seconds from a time
Now Returns current date and time
TimeSerial Returns a time from its parts
TimeValue Returns a time from its value
Declarations
Dim Declares a variable
Private Declares script-level private variable
Public Declares public-level public variable
ReDim Reallocates an array
Function Declares a function
Sub Declares a subprocedure
Error Handling
On Error Enables error handling
Err Contains information about last error
Input/Output
InputBox Prompts the user for input
MsgBox Displays a message to the user
Math
Atn Returns the Arctangent of a number
Cos Returns the cosine of a number
Sin Returns the sine of a number
Tan Returns the tangent of a number
Exp Returns the exponent of a number
Log Returns the logarithm of a number
Sqr Returns the square root of a number
Randomize Reseeds the randomizer
Rnd Returns a random number
Operators
+ Addition
- Subtraction
^ Exponentiation
Mod Modulus arithmetic
* Multiplication
/ Division
\ Integer Division
- Negation
& String concatenation
= Equality
<> Inequality
< Less Than
<= Less Than or Equal To
> Greater Than
>= Greater Than or Equal To
Is Compares expressions
And Compares expressions
Or Compares expressions
Xor Compares expressions
Eqv Compares expressions
Imp Compares expressions
Objects
CreateObject Creates reference to an OLE object
IsObject Returns True if object is valid
Options
Option Explicit Forces explicit variable declaration
Procedures
Call Invokes a subprocedure
Function Declares a function
Sub Declares a subprocedure
Strings
Instr Returns index of a string in another
InStrB Returns index of a string in another
Len Returns the length of a string
LenB Returns the length of a string
Lcase Converts a string to lowercase
Ucase Converts a string to uppercase
Left Returns the left portion of a string
LeftB Returns the left portion of a string
Mid Returns the mid portion of a string
MidB Returns the mid portion of a string
Right Returns the right portion of a string
RightB Returns the right portion of a string
Space Pads a string with spaces
StrComp Compares two strings
String Pads a string with a character
Ltrim Removes leading spaces from a string
Rtrim Removes trailing spaces from a string
Trim Removes leading and trailing spaces
Variants
IsArray Returns True if variable is an array
IsDate Returns True if variable is a date
IsEmpty Returns True if variable is empty
IsNull Returns True if variable is null.
IsNumeric Returns True if variable is a number
IsObject Returns True if variable is an object
VarType Indicates a variable's type

Visual Basic Keywords Omitted from VBScript

VBScript leaves out a bunch of Visual Basic keywords such as DoEvents, Print, and Shell. You can't read or write files, either, and you can't do much graphical programming. This won't stop you from creating great Web pages with VBScript, though, because VBScript provides every feature you need to do just about anything you want on the Web page. For example, you can dynamically change the contents of the Web page itself and you can interact with every object on the Web page.

Don't look at the list of omitted keywords and features yet. You need to understand why Microsoft didn't include them so that you'll understand why each feature is on this list. Take a look:

Table C.1 describes each keyword or feature available in Visual Basic but omitted from VBScript. I've divided this table into broad categories, with each entry under a category describing a single feature. I've used Microsoft's categories so that you can keep the list on Microsoft's Web site in sync with this list.


NOTE: The Internet Explorer Script Error dialog box tells you that it found a statement in your script which couldn't interpret. I'm sure that you've seen error messages such as "Expected while or until" or nested comments that just don't make any sense. When VBScript encounters a keyword it doesn't recognize, it spews out all sorts of garbage like the previous example. It usually points to the offending keyword, however, by placing a caret (^) directly underneath it. The next time you get one of these unexplained errors, look up the keyword in Table C.2 to see if Microsoft omitted it from VBScript.

Table C.2  Visual Basic Keywords Not in VBScript

Keyword/Feature Description
Array Handling
Option Base Declares default lower bound
Arrays with lower bound <> 0 All arrays must have 0 lower bound
Clipboard
Clipboard object Provides access to the clipboard
Clear Clears the contents of the clipboard
GetFormat Determines format of clipboard object
GetData Returns data from the clipboard
SetData Stores data in the clipboard
GetText Returns text from the clipboard
SetText Stores text in the clipboard
Collection
Add Adds an item to a collection
Count Returns number of items in collection
Item Returns an item from a collection
Remove Removes an item from a collection
Access collections using ! character Accesses a collection with !
Conditional Compilation
#Const Defines a compiler constant
#If...Then...#Else Conditional compilation
Constants/Literals
Const Defines a constant
All intrinsic Predefined constants such as vbOK constants
Exponent-based Real numbers using exponents real number
Trailing data type characters Defines data types implicitly
Control Flow
DoEvents Yields execution to Windows
GoSub...Return Branches to a label in a procedure
GoTo Goes to a label in a procedure
On Error GoTo Goes to a label on an error
On...GoSub Branches to a label on an index
On...GoTo Goes to a label on an index
Line numbers Line numbers
Line labels Labels define GoTo/GoSub targets
With...End With Provides easy access to an object
Conversion
Chr$ Returns a character from an ASCII code
Hex$ Returns string hex from a number
Oct$ Returns string octal from a number
Ccur Converts expression to currency
Cvar Converts expression to a variant
CVDate Converts an expression to a date
Format Formats a string
Format$ Formats a string
Str Returns a string form of a number
Str$ Returns a string form of a number
Val Returns a number from a string
Data Types
All intrinsic data types except variant Data types such as Date
Type...End Type Defines user-defined data type
Date/Time
Date statement Returns the current date
Time statement Returns the current time
Date$ Returns the current date
Time$ Returns the current time
Timer Returns seconds elapsed since midnight
DDE
LinkExecute Sends command during DDE conversation
LinkPoke Sends data during a DDE conversation
LinkRequest Receives data during DDE conversation
LinkSend Sends data during a DDE conversation
Debugging
Debug.Print Prints to the debugging window
End Shuts down the application
Stop Stops the application
Declaration
Declare Declares a DLL
Property Get Defines a user-defined class
Property Let Defines a user-defined class
Property Set Defines a user-defined class
Public Declares a public variable
Private Declares a private variable
ParamArray Accepts a variable number of arguments
Optional Specifies an optional argument
New Creates a new object
Error Handling
Erl Returns the line number of an error
Error Returns an error message
Error$ Returns an error message
On Error...Resume Enables error handling
Resume Resumes after an error
Resume Next Resumes after an error
File Input/Output
All Opens, reads, writes, and closes files
Financial
All financial Financial function such as Rate functions.
Graphics
Cls Clears the screen
Circle Draws a circle
Line Draws a line
Point Draws a point
Pset Changes a point's color
Scale Defines the coordinate system
Print Prints to a file
Spc Position output using Print
Tab Inserts a tab character
TextHeight Returns height of a text string
TextWidth Returns width of a text string
LoadPicture Loads a picture from disk
SavePicture Saves a picture to disk
QBColor Returns an RGB color code
RGB Combines RGB color codes
Manipulating Objects
Arrange Arranges windows
Zorder Changes z-order of windows
SetFocus Sets focus to a window
InputBox$ Prompts the user for a string
Drag Begins a drag-and-drop operation
Hide Hides a form
Show Shows a form
Load Loads a form
Unload Unloads a form
Move Moves a form
PrintForm Prints a form
Refresh Repaints a form
AddItem Adds item to list box
RemoveItem Removes item from a list box
Miscellaneous
Environ Returns the user's environment
Environ$ Returns the user's environment
SendKeys Sends keystrokes to a window
Command Returns the command line parameters
Command$ Returns the command line parameters
AppActivate Activates an application's window
Shell Launches another program
Beep Beeps the speaker
Object Manipulation
GetObject Returns an OLE object from a file
TypeOf Returns the type of an object
Operators
Like Compares to strings
Options
def type Sets default data type for variables
Option Base Sets default lower bound for arrays
Option Compare Defines default comparison method
Option Private Defines default scope module
Printing
TextHeight Returns height of a text string
TextWidth Returns width of a text string
EndDoc Terminates a print operation
NewPage Ejects the current page
PrintForm Prints a form
Strings
All fixed-length Strings with a fixed length
LCase$ Converts a string to lowercase
UCase$ Converts a string to uppercase
Lset Left-aligns a string
Rset Right-aligns a string
Space$ Pads a string with spaces
String$ Pads a string with a character
Format Formats a string
Format$ Formats a string
Left$ Returns left portion of a string
Mid$ Returns middle portion of a string
Right$ Returns right portion of a string
Mid Statement Replaces a portion of a string
Trim$ Removes leading and trailing spaces
LTrim$ Removes leading spaces from a string
RTrim$ Removes trailing spaces from a string
StrConv Performs various conversions
Using Classes
TypeName Defines a user-defined class
Optional Arguments
IsMissing Indicates missing optional argument


Previous chapterNext chapterContents


Macmillan Computer Publishing USA

© Copyright, Macmillan Computer Publishing. All rights reserved.