|  | The Complete Resource for All Web Builders

Search the site:
EXPERT SEARCH

| Programming Languages
| Databases
| Security
| Web Services
| Network Services
| Middleware
| Components
| Operating Systems
| User Interfaces
| Groupware & Collaboration
| Content Management
| Productivity Applications
| Hardware
| Fun & Games

EarthWeb sites
Crossnodes
Datamation
Developer.com
DICE
EarthWeb.com
EarthWeb Direct
ERP Hub
Gamelan
GoCertify.com
HTMLGoodies
Intranet Journal
IT Knowledge
IT Library
JavaGoodies
JARS
JavaScripts.com
open source IT
RoadCoders
Y2K Info

- C — VBScript Syntax Quick Reference

#
C — VBScript Syntax Quick Reference

VBScript is composed of a great deal of syntax you need to keep straight. You will probably use many elements of the syntax so often that you will easily remember what they do. However, even an experienced programmer uses some of the syntax elements infrequently. When you come across those elements in your code or strain to remember if you have the syntax exactly right, a good reference can serve as a welcome relief.

Languages such as Visual Basic 4.0 come complete with a very useful context-sensitive help facility. VBScript provides no such inherent support. It is a hosted language that comes along for the ride with the environment that supports it, such as a browser. It is not a separate product with its own development environment and the help that is typical of such an environment. You can turn to other places for help on the Internet, however. At the time of this writing, Microsoft had a very helpful VBScript language reference that could be reached under http://www.microsoft.com/vbscript.

This appendix is intended to supplement the VBScript information available from the Web location. Unlike some of the other language references available, the information in this appendix is presented in a strict alphabetical fashion, intermixing functions, statements, See Prior Notes, and major properties in the same list. A brief description of each element is provided, but it's not enough to replace the official reference material—just enough to give you a quick high-level understanding of what that element does.

You'll develop a common way to refer to information as you work your way through a new book or sample programs. You might find a language element that is unfamiliar, but all you need to do to quickly get back on course is see a brief description of what it does and find out if it is a property, function, or other type of construct. This appendix can serve as a quick first resort for such information.

Table C.1. Summary of VBScript syntax.

    Symbol
    Type
    Description
+ (addition) | Operator | Adds two numbers together. You can also use this to concatenate strings.
' (comment indicator) | Keyword | What follows this symbol on the line is a comment.
" (double quote) | Keyword | Denotes the start and end of a literal string.
& (string concatenation) | Operator | Performs the concatenation of two string expressions.
/ (division, floating point) | Operator | Divides two numbers and returns a floating-point result.
\ (division, integer) | Operator | Divides two numbers and returns an integer result.
= (equals) comparison |  | Checks whether two expressions are equivalent.
^ (exponent) | Operator | Raises a number to the power of an exponent.
> (greater than) | Comparison | Checks whether the left-side expression is greater than the right-side expression.
>= (greater than or equal) | Comparison | Checks whether the left-side expression is greater than or equal to the right-side expression.
< (less than) | Comparison | Checks whether the left-side expression is less than the right-side expression.
<= (less than or equal) | Comparison | Checks whether the left-side expression is less than or equal to the right-side expression.
_ (line continuation character) | Keyword | Indicates that the current line continues onto the next line.
* (multiplication) | Operator | Multiplies two numbers.
- (subtraction or negation) | Operator | Finds the difference between two numbers, or when applied to one operand, treats it as a negative value.
: (colon) |  | Indicates line separation, as in A = A + 1 : B = C + 1.
<> (not equal) | Comparison | Checks whether two expressions are not equivalent.
Abs | Function | Returns the absolute value of a number.
And | Logical | Performs a logical conjunction on two expressions.
Array | Function | Returns a variant comprising an array.
Asc | Function | Provides the character code corresponding to the first letter in a string as a return code.
AscB | Function | Like Asc, but it returns the first byte rather than the first character of a string.
Atn | Function | Provides the arctangent of a number as a return code.
Call | Statement | Calls a procedure.
CBool | Function | Provides as a return code an expression that has been converted to a variant of subtype Boolean.
Cbyte | Function | Provides as a return code an expression that has been converted to a variant of subtype Byte.
CDate | Function | Provides as a return code an expression that has been converted to a variant of subtype Date.
CDbl | Function | Provides as a return code an expression that has been converted to a variant of subtype Double.
Chr | Function | Provides as a return code the character associated with the ASCII code. This function can return one or two bytes.
ChrB | Function | Returns the byte associated with the ASCII code.
Cint | Function | Provides as a return code an expression that has been converted to a variant of subtype Integer.
Clear | Method for the Err object | Results in resetting all of the Err objects properties to a no-error state.
CLng | Function | Provides as a return code an expression that has been converted to a variant of subtype Long.
Cos | Function | Provides as a return code the cosine of an angle.
CSng | Function | Provides as a return code an expression that has been converted to a variant of subtype Single.
CStr | Function | Provides as a return code an expression that has been converted to a variant of subtype String.
CVErr | Function | Provides as a return code a variant of subtype Error containing a user-provided error code.
Date | Function | Returns the current system date.
DateSerial | Function | Provides as a return code a variant of subtype Date for the given month, day, and year.
DateValue | Function | Provides as a return code a variant of subtype Date for the given string.
Day | Function | Provides as a return code a whole number of 1 through 31, representing the day of the month for the given date string.
Description | Property for the Err object | The string that describes the current error.
Dim | Statement | Declares variables.
Do...Loop | Statement | Repeats a block of code while a condition is True or until a condition becomes True.
Empty | Literal | Signifies that a variable is uninitialized.
Erase | Statement | Reinitializes fixed-size array elements and frees the storage space of dynamic arrays.
Err | Object | Provides information about run-time errors.
Eqv | Logical operator | Performs logical equivalence for the two expressions provided as operands.
Exit Do | Statement | Exits a Do. . .Loop code block.
Exit For | Statement | Exits a For. . .Next code block.
Exit Function | Statement | Exits a function.
Exit Sub | Statement | Exits a procedure.
Exp | Function | Returns e (the base of natural logarithms) raised to a power.
Fix | Function | Provides the integer portion of a number as a return code; if the number is negative, it provides the first number greater than the operand.
For. . .Next | Statement | Repeats a group of statements a designated number of times.
For Each. . .Next | Statement | Repeats a group of statements for each element in an array or collection.
Function | Statement | Declares a procedure-level block of code that returns a value when called.
HelpContext | Property for the Err object | The context ID in a corresponding help file for the current error.
HelpFile | Property for the Err object | The corresponding help file for the current error.
Hex | Function | Provides as a return code a string representing the hexadecimal value of a number.
Hour | Function | Provides as a return code a whole number from 0 through 23, representing the hour of the day.
If. . .Then. . .Else | Statement | Executes a group of statements, depending on the value of an expression.
Imp | Logical operator | Performs a logical implication on the two operands provided.
InputBox | Function | Displays a dialog box with a prompt, appropriate buttons, and an input text box and then returns the input text and button response to calling program.
Int | Function | Provides the integer portion of a number as a return code; if the number is negative, it provides first number less than the operand.
InStr | Function | Provides the position indicator of the first character of the target string within the search string.
InstrB | Function | Provides the position indicator of the first byte of the target string within the search string.
Is | Operator | Compares two object reference variables.
IsArray | Function | Provides as a return code a Boolean value signifying whether a variable is an array.
IsDate | Function | Provides as a return code a Boolean value signifying whether an expression can be converted to a date.
IsEmpty | Function | Provides as a return code a Boolean value signifying whether a variable has been initialized.
IsError | Function | Provides as a return code a Boolean value signifying whether an expression is an error value.
IsNull | Function | Provides as a return code a Boolean value signifying whether an expression contains no valid data (Null).
IsNumeric | Function | Provides as a return code a Boolean value signifying whether an expression can be evaluated as a number.
IsObject | Function | Provides as a return code a Boolean value signifying whether an expression represents an OLE automation object.
LBound | Function | Provides as a return code the smallest available subscript for the stated dimension of an array.
Lcase | Function | Provides as a return code a string that has been converted to lowercase.
Left | Function | Provides as a return code a specified number of characters from the left side of a string.
Len | Function | Provides as a return code the number of characters in a string or the number of bytes required to store a variable.
LenB | Function | Provides as a return code the number of bytes in a string or the number of bytes required to store a variable.
Log | Function | Provides as a return code the natural logarithm of a number.
Ltrim | Function | Provides a string that has leading (leftmost) spaces removed.
Mid | Function | Provides as a return code a described number of characters from a string.
Minute | Function | Provides as a return code a whole number from 0 through 59, representing the minute of the hour.
Mod | Operator | Divides two numbers and returns only the remainder.
Month | Function | Provides as a return code a whole number from 1 through 12, representing the month of the year.
MsgBox | Function | Shows a given prompt in a message dialog box with a button and returns the user's button response.
Not | Logical operator | Checks for logical not equivalent condition.
Nothing | Literal | Removes reference and frees memory.
Now | Function | Returns the current setting of your computer's system date and time.
Null | Literal | Indicates no valid data state, as opposed to Empty, which indicates no data was ever assigned.
Number | Property for the Err object | The numeric error code for the current error.
Oct | Function | Provides as a return code a string representing the octal value of a number.
On Error Resume Next | Statement | Indicates that if an error occurs, control should resume at next statement.
Option Explicit | Statement | Indicates that variables must be declared.
Or | Operator | Performs a logical disjunction on two expressions.
Raise | Method for the Err object | Forces a run-time error to be raised.
Randomize | Statement | Starts a sequence for the random-number generator.
ReDim | Statement | Allocates or reallocates storage space and declares dynamic-array variables at the procedure level.

Rem | Statement | Used to include comments in a program. The single quote that achieves the same purpose is used more often.
Right | Function | Provides as a return code a described number of characters from the right side of a string.
Rnd | Function | Provides a random number as a return code.
Rtrim | Function | Provides a string that has trailing (rightmost) spaces removed.
Second | Function | Provides as a return code a whole number from 0 through 59, representing the second of the minute.
Set | Statement | Assigns an object reference.
Sgn | Function | Provides as a return code an integer disclosing the sign of a number.
Sin | Function | Provides as a return code the sine of an angle.
Source | Property for the Err object | The source of the error for the current error.
Space | Function | Returns the given number of spaces.
Sqr | Function | Provides as a return code the square root of a number.
Static | Statement (Procedure-level) | Declares a persistent variable. Contents will be retained from one call to the next.
StrComp | Function | Returns a value signifying the outcome of a string comparison.
String | Function | Returns a repeating character string of the number of characters described.
Sub | Statement | Declares procedures that do not provide a return code.
Tan | Function | Provides as a return code the tangent of an angle.
Time | Function | Returns a variant of subtype Date showing the current system time.
TimeSerial | Function | Returns a variant of subtype Date comprising the time for a specific hour, minute, and second.
TimeValue | Function | Returns a variant of subtype Date containing the time.
Trim | Function | Provides as a return code a duplicate of a string without leading spaces (LTrim), trailing spaces (RTrim), or both leading and trailing spaces (Trim).
Ubound | Function | Provides as a return code the largest available subscript for the indicated dimension of an array.
Ucase | Function | Returns a string that has been converted to uppercase.
Val | Function | Returns the numbers enclosed in a string. Not supported in current beta.
VarType | Function | Returns a value disclosing the subtype of a variable.
vbAbort* | (See footnote*) | Applies to the MsgBox function; Value = 3 indicates abort.
vbAbortRetryIgnore | (See footnote*) | Applies to the MsgBox function; Value = 2 displays Abort, Retry, and Ignore buttons
vbApplicationModal | (See footnote*) | Applies to the MsgBox function; Value = 0 indicates that the application is modal. The user must respond to the message box before continuing work in the current application.
vbArray | (See footnote*) | Applies to the VarType function; Value = 8192 indicates array.
vbBoolean | (See footnote*) | Applies to the VarType function; Value = 11 indicates Boolean.
vbByte | (See footnote*) | Applies to the VarType function; Value = 17 indicates byte.
vbCancel | (See footnote*) | Applies to the MsgBox function; Value = 2 indicates cancel.
vbCr | (See footnote*) | General purpose; indicates carriage-return character.
vbCritical | (See footnote*) | Applies to the MsgBox function; Value = 16 displays critical message icon.
vbCrLf | (See footnote*) | General purpose; indicates carriage-return and line-feed characters.
vbCurrency | (See footnote*) | Applies to the VarType function; Value = 6 indicates currency.
vbDataObject | (See footnote*) | Applies to the VarType function; Value = 13 indicates non-OLE automation object.
vbDate | (See footnote*) | Applies to the VarType function; Value = 7 indicates date.
vbDefaultButton1 | (See footnote*) | Applies to the MsgBox function; Value = 0 indicates the first button is the default.
vbDefaultButton2 | (See footnote*) | Applies to the MsgBox function; Value = 256 indicates the second button is the default.
vbDefaultButton3 | (See footnote*) | Applies to the MsgBox function; Value = 512 indicates the third button is the default.
vbDouble | (See footnote*) | Applies to the VarType function; Value = 5 indicates a double-precision, floating-point number.
vbEmpty | (See footnote*) | Applies to the VarType function, Value = 0 indicates empty.
vbError | (See footnote*) | Applies to the VarType function; Value = 10 indicates error.
vbExclamation | (See footnote*) | Applies to the MsgBox function; Value = 48 displays the warning message icon.
vbFalse | (See footnote*) | General purpose; indicates Boolean value represented by 0.
vbFriday | (See footnote*) | Applies to the Weekday function; Value = 6 indicates Friday.
vbIgnore | (See footnote*) | Applies to the MsgBox function; Value = 5 indicates ignore.
vbInformation | (See footnote*) | Applies to the MsgBox function; Value = 64 displays information message icon.
vbInteger | (See footnote*) | Applies to the VarType function; Value = 2 indicates integer.
vbLf | (See footnote*) | General purpose; indicates line-feed character.
vbLong | (See footnote*) | Applies to the VarType function; Value = 3 indicates long integer.
vbMonday | (See footnote*) | Applies to the Weekday function; Value = 2 indicates Monday.
vbNo | (See footnote*) | Applies to the MsgBox function; Value = 7 indicates no.
vbNull | (See footnote*) | Applies to the VarType function; Value = 1 indicates null.
vbObject | (See footnote*) | Applies to the VarType function; Value = 9 indicates OLE automation object.
vbObjectError | (See footnote*) | Indicates an object-generated error.
vbOK | (See footnote*) | Applies to the MsgBox function; Value = 1 indicates OK.
vbOKCancel | (See footnote*) | Applies to MsgBox function; Value = 1 displays OK and Cancel buttons.
vbOKOnly | (See footnote*) | Applies to the MsgBox function; Value = 0 displays OK button only.
vbQuestion | (See footnote*) | Applies to the MsgBox function; Value = 32 displays warning query icon.
vbRetry | (See footnote*) | Applies to the MsgBox function; Value = 4 indicates retry.
vbRetryCancel | (See footnote*) | Applies to the MsgBox function; Value = 5 displays retry and cancel buttons.
vbSaturday | (See footnote*) | Applies to the Weekday function; Value = 7 indicates Saturday.
vbSingle | (See footnote*) | Applies to the VarType function; Value = 4 indicates single-precision, floating-point number.
vbString | (See footnote*) | Applies to the VarType function; Value = 8 indicates string.
vbSunday | (See footnote*) | Applies to the Weekday function; Value = 1 indicates Sunday.
vbSystemModal | (See footnote*) | Applies to the MsgBox function; Value = 4096 indicates system modal. All applications are suspended until the user responds to the message box.
vbThursday | (See footnote*) | Applies to the Weekday function; Value = 5 indicates Thursday.
vbTrue | (See footnote*) | General purpose; indicates Boolean value represented by -1.
vbTuesday | (See footnote*) | Applies to the Weekday function; Value = 3 indicates Tuesday.
vbUseSystem | (See footnote*) | Applies to the Weekday function; Value = 0 uses the NLS API setting.
vbVariant | (See footnote*) | Applies to the VarType function; Value = 12 indicates variant.
vbWednesday | (See footnote*) | Applies to the Weekday function; Value = 4 indicates Wednesday.
vbYes | (See footnote*) | Applies to the MsgBox function; Value = 6 indicates yes.
vbYesNo | (See footnote*) | Applies to the MsgBox function; Value = 4 displays yes and no buttons.
vbYesNoCancel | (See footnote*) | Applies to the MsgBox function; Value = 3 displays yes, no, and cancel buttons.
Weekday | Function | Returns a whole number showing the day of the week.
While. . .Wend | Statement | Performs a series of statements as long as a given condition is True.
Xor | Logical operator | Performs logical exclusion on the operands.
Year | Function | Returns a whole number showing the year for the date string representation.

*The symbols with the vb prefix are values expected by various VBScript functions. In Visual Basic these are intrinsic contants. In VBScript, you must declare these as variables if you wish to treat them as constants since there is no direct constant support.

| Use of this site is subject certain Terms & Conditions. Copyright (c) 1996-1999 EarthWeb, Inc.. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Please read our privacy policy for details.