VBScript Language Reference

Office VBScript

Microsoft® Visual Basic® Scripting Edition VBScript Language Reference  VBScript Tutorial 
 Version Information 



 Feature Information

 Alphabetic Keyword List

 Constants

 Errors

 Events

 Functions

 Methods

 Objects

 Operators

 Properties

 Statements

 

Welcome to the VBScript Language Reference

These handy blocks of information will help you explore the many different parts of the Visual Basic Scripting language.

You'll find all the parts of the VBScript language listed alphabetically under the Alphabetic Keyword List. But if you want to examine just one category, say, objects, each language category has its own, more compact section.

How's it work? Click on one of the headings to the left to display a list of items contained in that category. From this list, select the topic that you want to view. Once you've opened that topic, you can easily link to other related sections.

So, go ahead and take a look! Study some statements, mull over the methods, or figure out a few functions. You'll see just how versatile the VBScript language can be!

Features
Description
Version Information
List of VBScript versions by host application and list of features by version.
VBScript Features
List of features currently in VBScript.
VBA Features not in VBScript
List of features currently in Visual Basic: Applications Edition but not in VBScript.
VBScript Features not in VBA List of features in VBScript that are not in Visual Basic: Applications Edition.
Microsoft Scripting Run-Time Features List of scripting run-time features currently in VBScript.
Language Element
Description
Abs Function Returns the absolute value of a number.
Addition Operator (+) Sums two numbers.
And Operator Performs a logical conjunction on two expressions.
Array Function Returns a Variant containing an array.
Asc Function Returns the ANSI character code corresponding to the first letter in a string.
Assignment Operator (=) Assigns a value to a variable or property.
Atn Function Returns the arctangent of a number.
Call Statement Transfers control to a Sub or Function procedure.
CBool Function Returns an expression that has been converted to a Variant of subtype Boolean.
CByte Function Returns an expression that has been converted to a Variant of subtype Byte.
CCur Function Returns an expression that has been converted to a Variant of subtype Currency.
CDate Function Returns an expression that has been converted to a Variant of subtype Date.
CDbl Function Returns an expression that has been converted to a Variant of subtype Double.
Chr Function Returns the character associated with the specified ANSI character code.
CInt Function Returns an expression that has been converted to a Variant of subtype Integer.
Class Object Provides access to the events of a created class.
Class Statement Declares the name of a class.
Clear Method Clears all property settings of the Err object.
CLng Function Returns an expression that has been converted to a Variant of subtype Long.
Color Constants List of color constants.
Comparison Constants List of constants used in comparison operations.
Concatenation Operator (&) Forces string concatenation of two expressions.
Const Statement Declares constants for use in place of literal values.
Cos Function Returns the cosine of an angle.
CreateObject Function Creates and returns a reference to an Automation object.
CSng Function Returns an expression that has been converted to a Variant of subtype Single.
CStr Function Returns an expression that has been converted to a Variant of subtype String.
Date and Time Constants List of constants defining days of week and other constants used in Date and Time operations.
Date Format Constants List of constants used to format dates and times.
Date Function Returns the current system date.
DateAdd Function Returns a date to which a specified time interval has been added.
DateDiff Function Returns the number of intervals between two dates.
DatePart Function Returns the specified part of a given date.
DateSerial Function Returns a Variant of subtype Date for a specified year, month, and day.
DateValue Function Returns a Variant of subtype Date.
Day Function Returns a whole number between 1 and 31, inclusive, representing the day of the month.
Description Property Returns or sets a descriptive string associated with an error.
Dictionary Object Object that stores data key, item pairs.
Dim Statement Declares variables and allocates storage space.
Division Operator (/) Divides two numbers and returns a floating-point result.
Do...Loop Statement Repeats a block of statements while a condition is True or until a condition becomes True.
Empty Indicates an uninitialized variable value.
Eqv Operator Performs a logical equivalence on two expressions.
Erase Statement Reinitializes the elements of fixed-size arrays and deallocates dynamic-array storage space.
Err Object Contains information about run-time errors.
Eval Function Evaluates an expression and returns the result.
Execute Method Executes a regular expression search against a specified string.
Execute Statement Executes one or more specified statements.
ExecuteGlobal Statement Executes one or more specified statements in the global namespace of a script.
Exit Statement Exits a block of Do...Loop, For...Next, Function, or Sub code.
Exp Function Returns e (the base of natural logarithms) raised to a power.
Exponentiation Operator (^) Raises a number to the power of an exponent.
False Keyword that has a value equal to zero.
FileSystemObject Object Provides access to a computer's file system.
Filter Function Returns a zero-based array containing a subset of a string array based on a specified filter criteria.
FirstIndex Property Returns the position in a search string where a match occurs.
Fix Function Returns the integer portion of a number.
For...Next Statement Repeats a group of statements a specified number of times.
For Each...Next Statement Repeats a group of statements for each element in an array or collection.
FormatCurrency Function Returns an expression formatted as a currency value using the currency symbol defined in the system control panel.
FormatDateTime Function Returns an expression formatted as a date or time.
FormatNumber Function Returns an expression formatted as a number.
FormatPercent Function Returns an expression formatted as a percentage (multiplied by 100) with a trailing % character.
Function Statement Declares the name, arguments, and code that form the body of a Function procedure.
GetLocale Function Returns the current locale ID value.
GetObject Function Returns a reference to an Automation object from a file.
GetRef Function Returns a reference to a procedure that can be bound to an event.
Global Property Sets or returns a Boolean value.
Hex Function Returns a string representing the hexadecimal value of a number.
HelpContext Property Sets or returns a context ID for a topic in a Help File.
HelpFile Property Sets or returns a fully qualified path to a Help File
Hour Function Returns a whole number between 0 and 23, inclusive, representing the hour of the day.
If...Then...Else Statement Conditionally executes a group of statements, depending on the value of an expression.
IgnoreCase Property Sets or returns a Boolean value that indicates if a pattern search is case-sensitive or not.
Imp Operator Performs a logical implication on two expressions.
Initialize Event
Occurs when an instance of the associated class is created.
InputBox Function Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.
InStr Function Returns the position of the first occurrence of one string within another.
InStrRev Function Returns the position of an occurrence of one string within another, from the end of string.
Int Function Returns the integer portion of a number.
Integer Division Operator (\) Divides two numbers and returns an integer result.
Is Operator Compares two object reference variables.
IsArray Function Returns a Boolean value indicating whether a variable is an array.
IsDate Function Returns a Boolean value indicating whether an expression can be converted to a date.
IsEmpty Function Returns a Boolean value indicating whether a variable has been initialized.
IsNull Function Returns a Boolean value that indicates whether an expression contains no valid data (Null).
IsNumeric Function Returns a Boolean value indicating whether an expression can be evaluated as a number.
IsObject Function Returns a Boolean value indicating whether an expression references a valid Automation object.
Join Function Returns a string created by joining a number of substrings contained in an array.
LBound Function Returns the smallest available subscript for the indicated dimension of an array.
LCase Function Returns a string that has been converted to lowercase.
Locale ID (LCID) Chart List of Locale ID's and their associated values.
Left Function Returns a specified number of characters from the left side of a string.
Len Function Returns the number of characters in a string or the number of bytes required to store a variable.
Length Property Returns the length of a match found in a search string.
LoadPicture Function Returns a picture object. Available only on 32-bit platforms.
Log Function Returns the natural logarithm of a number.
LTrim Function Returns a copy of a string without leading spaces.
Match Object Provides access to the read-only properties of a regular expression match.
Matches Collection Collection of regular expression Match objects.
Mid Function Returns a specified number of characters from a string.
Minute Function Returns a whole number between 0 and 59, inclusive, representing the minute of the hour.
Miscellaneous Constants List of constants that don't fit into any other category.
Mod Operator Divides two numbers and returns only the remainder.
Month Function Returns a whole number between 1 and 12, inclusive, representing the month of the year.
MonthName Function Returns a string indicating the specified month.
MsgBox Constants List of constants used with the MsgBox Function.
MsgBox Function Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.
Multiplication Operator (*) Multiplies two numbers.
Negation Operator (-) Indicates the negative value of a numeric expression.
Not Operator Performs logical negation on an expression.
Now Function Returns the current date and time according to the setting of your computer's system date and time.
Nothing Disassociates an object variable from any actual object.
Null Indicates that a variable contains no valid data.
Number Property Returns or sets a numeric value specifying an error.
Oct Function Returns a string representing the octal value of a number.
On Error Statement Enables error-handling.
Operator Precedence List showing the order of precedence for various operators used in VBScript.
Option Explicit Statement Forces explicit declaration of all variables in a script.
Or Operator Performs a logical disjunction on two expressions.
Pattern Property Sets or returns the regular expression pattern being searched for.
Private Statement Declares private variables and allocates storage space.
PropertyGet Statement Declares the name, arguments, and code that form the body of a Property procedure that gets (returns) the value of a property.
PropertyLet Statement Declares the name, arguments, and code that form the body of a Property procedure that assigns the value of a property.
PropertySet Statement Declares the name, arguments, and code that form the body of a Property procedure that sets a reference to an object.
Public Statement Declares public variables and allocates storage space.
Raise Method Generates a run-time error.
Randomize Statement Initializes the random-number generator.
ReDim Statement Declares dynamic-array variables, and allocates or reallocates storage space at procedure level.
RegExp Object Provides simple regular expression support.
Rem Statement Includes explanatory remarks in a program.
Replace Function Returns a string in which a specified substring has been replaced with another substring a specified number of times.
Replace Method Replaces text found in a regular expression search.
RGB Function Returns a whole number representing an RGB color value.
Right Function Returns a specified number of characters from the right side of a string.
Rnd Function Returns a random number.
Round Function Returns a number rounded to a specified number of decimal places.
Run-time Errors List VBScript run-time errors.
RTrim Function Returns a copy of a string without trailing spaces.
ScriptEngine Function Returns a string representing the scripting language in use.
ScriptEngineBuildVersion Function Returns the build version number of the scripting engine in use.
ScriptEngineMajorVersion Function Returns the major version number of the scripting engine in use.
ScriptEngineMinorVersion Function Returns the minor version number of the scripting engine in use.
Second Function Returns a whole number between 0 and 59, inclusive, representing the second of the minute.
Select Case Statement Executes one of several groups of statements, depending on the value of an expression.
Set Statement Assigns an object reference to a variable or property.
SetLocale Function Sets the global locale and returns the previous locale.
Sgn Function Returns an integer indicating the sign of a number.
Sin Function Returns the sine of an angle.
Source Property Returns or sets the name of the object or application that originally generated the error.
Space Function Returns a string consisting of the specified number of spaces.
Split Function Returns a zero-based, one-dimensional array containing a specified number of substrings.
Sqr Function Returns the square root of a number.
StrComp Function Returns a value indicating the result of a string comparison.
String Constants List of string constants.
String Function Returns a repeating character string of the length specified.
StrReverse Function Returns a string in which the character order of a specified string is reversed.
Sub Statement Declares the name, arguments, and code that form the body of a Sub procedure.
Subtraction Operator (-) Finds the difference between two numbers or indicates the negative value of a numeric expression.
Syntax Errors List VBScript syntax errors.
Tan Function Returns the tangent of an angle.
Terminate Event
Occurs when an instance of the associated class is terminated.
Test Method Executes a regular expression search against a specified string.
Time Function Returns a Variant of subtype Date indicating the current system time.
Timer Function Returns the number of seconds that have elapsed since 12:00 AM (midnight).
TimeSerial Function Returns a Variant of subtype Date containing the time for a specific hour, minute, and second.
TimeValue Function Returns a Variant of subtype Date containing the time.
Trim Function Returns a copy of a string without leading or trailing spaces.
Tristate Constants Use them anywhere in your code to represent the values shown for each.
True Keyword that has a value equal to -1.
TypeName Function Returns a string that provides Variant subtype information about a variable.
UBound Function Returns the largest available subscript for the indicated dimension of an array.
UCase Function Returns a string that has been converted to uppercase.
Value Property Returns the value or text of a match found in a search string.
VarType Constants List of constants that define Variant subtypes.
VarType Function Returns a value indicating the subtype of a variable.
VBScript Constants Various categories of constants provided in VBScript.
Weekday Function Returns a whole number representing the day of the week.
WeekdayName Function Returns a string indicating the specified day of the week.
While...Wend Statement Executes a series of statements as long as a given condition is True.
With Statement Executes a series of statements on a single object.
Xor Operator Performs a logical exclusion on two expressions.
Year Function Returns a whole number representing the year.
Language Element
Description
Color Constants List of color constants.
Comparison Constants List of constants used in comparison operations.
Date and Time Constants List of constants defining days of week and other constants used in Date and Time operations.
Date Format Constants List of constants used to format dates and times.
Locale ID (LCID) Chart List of Locale ID's and their associated values.
Miscellaneous Constants List of constants that don't fit into any other category.
MsgBox Constants List of constants used with the MsgBox Function.
String Constants List of string constants.
Tristate Constants Use them anywhere in your code to represent the values shown for each.
VarType Constants List of constants that define Variant subtypes.
VBScript Constants Various categories of constants provided in VBScript.
Errors
Description
Run-time Errors
List of VBScript run-time errors.
Syntax Errors
List of VBScript syntax errors.
Language Element
Description
Initialize Event
Occurs when an instance of the associated class is created.
Terminate Event
Occurs when an instance of the associated class is terminated.
Language Element
Description
Abs Function Returns the absolute value of a number.
Array Function Returns a Variant containing an array.
Asc Function Returns the ANSI character code corresponding to the first letter in a string.
Atn Function Returns the arctangent of a number.
CBool Function Returns an expression that has been converted to a Variant of subtype Boolean.
CByte Function Returns an expression that has been converted to a Variant of subtype Byte.
CCur Function Returns an expression that has been converted to a Variant of subtype Currency.
CDate Function Returns an expression that has been converted to a Variant of subtype Date.
CDbl Function Returns an expression that has been converted to a Variant of subtype Double.
Chr Function Returns the character associated with the specified ANSI character code.
CInt Function Returns an expression that has been converted to a Variant of subtype Integer.
CLng Function Returns an expression that has been converted to a Variant of subtype Long.
Cos Function Returns the cosine of an angle.
CreateObject Function Creates and returns a reference to an Automation object.
CSng Function Returns an expression that has been converted to a Variant of subtype Single.
CStr Function Returns an expression that has been converted to a Variant of subtype String.
Date Function Returns the current system date.
DateAdd Function Returns a date to which a specified time interval has been added.
DateDiff Function Returns the number of intervals between two dates.
DatePart Function Returns the specified part of a given date.
DateSerial Function Returns a Variant of subtype Date for a specified year, month, and day.
DateValue Function Returns a Variant of subtype Date.
Day Function Returns a whole number between 1 and 31, inclusive, representing the day of the month.
Eval Function Evaluates an expression and returns the result.
Exp Function Returns e (the base of natural logarithms) raised to a power.
Filter Function Returns a zero-based array containing subset of a string array based on a specified filter criteria.
Fix Function Returns the integer portion of a number.
FormatCurrency Function Returns an expression formatted as a currency value using the currency symbol defined in the system control panel.
FormatDateTime Function Returns an expression formatted as a date or time.
FormatNumber Function Returns an expression formatted as a number.
FormatPercent Function Returns an expression formatted as a percentage (multiplied by 100) with a trailing % character.
GetLocale Function Returns the current locale ID value.
GetObject Function Returns a reference to an Automation object from a file.
GetRef Function Returns a reference to a procedure that can be bound to an event.
Hex Function Returns a string representing the hexadecimal value of a number.
Hour Function Returns a whole number between 0 and 23, inclusive, representing the hour of the day.
InputBox Function Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.
InStr Function Returns the position of the first occurrence of one string within another.
InStrRev Function Returns the position of an occurrence of one string within another, from the end of string.
Int Function Returns the integer portion of a number.
IsArray Function Returns a Boolean value indicating whether a variable is an array.
IsDate Function Returns a Boolean value indicating whether an expression can be converted to a date.
IsEmpty Function Returns a Boolean value indicating whether a variable has been initialized.
IsNull Function Returns a Boolean value that indicates whether an expression contains no valid data (Null).
IsNumeric Function Returns a Boolean value indicating whether an expression can be evaluated as a number.
IsObject Function Returns a Boolean value indicating whether an expression references a valid Automation object.
Join Function Returns a string created by joining a number of substrings contained in an array.
LBound Function Returns the smallest available subscript for the indicated dimension of an array.
LCase Function Returns a string that has been converted to lowercase.
Left Function Returns a specified number of characters from the left side of a string.
Len Function Returns the number of characters in a string or the number of bytes required to store a variable.
LoadPicture Function Returns a picture object. Available only on 32-bit platforms.
Log Function Returns the natural logarithm of a number.
LTrim Function Returns a copy of a string without leading spaces.
Mid Function Returns a specified number of characters from a string.
Minute Function Returns a whole number between 0 and 59, inclusive, representing the minute of the hour.
Month Function Returns a whole number between 1 and 12, inclusive, representing the month of the year.
MonthName Function Returns a string indicating the specified month.
MsgBox Function Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.
Now Function Returns the current date and time according to the setting of your computer's system date and time.
Oct Function Returns a string representing the octal value of a number.
Replace Function Returns a string in which a specified substring has been replaced with another substring a specified number of times.
RGB Function Returns a whole number representing an RGB color value.
Right Function Returns a specified number of characters from the right side of a string.
Rnd Function Returns a random number.
Round Function Returns a number rounded to a specified number of decimal places.
RTrim Function Returns a copy of a string without trailing spaces.
ScriptEngine Function Returns a string representing the scripting language in use.
ScriptEngineBuildVersion Function Returns the build version number of the scripting engine in use.
ScriptEngineMajorVersion Function Returns the major version number of the scripting engine in use.
ScriptEngineMinorVersion Function Returns the minor version number of the scripting engine in use.
Second Function Returns a whole number between 0 and 59, inclusive, representing the second of the minute.
SetLocale Function Sets the global locale and returns the previous locale.
Sgn Function Returns an integer indicating the sign of a number.
Sin Function Returns the sine of an angle.
Space Function Returns a string consisting of the specified number of spaces.
Split Function Returns a zero-based, one-dimensional array containing a specified number of substrings.
Sqr Function Returns the square root of a number.
StrComp Function Returns a value indicating the result of a string comparison.
String Function Returns a repeating character string of the length specified.
StrReverse Function Returns a string in which the character order of a specified string is reversed.
Tan Function Returns the tangent of an angle.
Time Function Returns a Variant of subtype Date indicating the current system time.
Timer Function Returns the number of seconds that have elapsed since 12:00 AM (midnight).
TimeSerial Function Returns a Variant of subtype Date containing the time for a specific hour, minute, and second.
TimeValue Function Returns a Variant of subtype Date containing the time.
Trim Function Returns a copy of a string without leading or trailing spaces.
TypeName Function Returns a string that provides Variant subtype information about a variable.
UBound Function Returns the largest available subscript for the indicated dimension of an array.
UCase Function Returns a string that has been converted to uppercase.
VarType Function Returns a value indicating the subtype of a variable.
Weekday Function Returns a whole number representing the day of the week.
WeekdayName Function Returns a string indicating the specified day of the week.
Year Function Returns a whole number representing the year.
Language Element
Description
Clear Method Clears all property settings of the Err object.
Execute Method Executes a regular expression search against a specified string.
Raise Method Generates a run-time error.
Replace Method Replaces text found in a regular expression search.
Test Method Executes a regular expression search against a specified string.
Language Element
Description
Class Object Provides access to the events of a created class.
Dictionary Object Object that stores data key, item pairs.
Err Object Contains information about run-time errors.
FileSystemObject Object Provides access to a computer's file system.
Match Object Provides access to the read-only properties of a regular expression match.
Matches Collection Collection of regular expression Match objects.
RegExp Object Provides simple regular expression support.
Language Element
Description
Addition Operator (+) Sums two numbers.
And Operator Performs a logical conjunction on two expressions.
Assignment Operator (=) Assigns a value to a variable or property.
Concatenation Operator (&) Forces string concatenation of two expressions.
Division Operator (/) Divides two numbers and returns a floating-point result.
Eqv Operator Performs a logical equivalence on two expressions.
Exponentiation Operator (^) Raises a number to the power of an exponent.
Imp Operator Performs a logical implication on two expressions.
Integer Division Operator (\) Divides two numbers and returns an integer result.
Is Operator Compares two object reference variables.
Mod Operator Divides two numbers and returns only the remainder.
Multiplication Operator (*) Multiplies two numbers.
Negation Operator (-) Indicates the negative value of a numeric expression.
Not Operator Performs logical negation on an expression.
Operator Precedence List showing the order of precedence for various operators used in VBScript.
Or Operator Performs a logical disjunction on two expressions.
Subtraction Operator (-) Finds the difference between two numbers or indicates the negative value of a numeric expression.
Xor Operator Performs a logical exclusion on two expressions.
Language Element
Description
Description Property Returns or sets a descriptive string associated with an error.
FirstIndex Property Returns the position in a search string where a match occurs.
Global Property Sets or returns a Boolean value.
HelpContext Property Sets or returns a context ID for a topic in a Help File.
HelpFile Property Sets or returns a fully qualified path to a Help File
IgnoreCase Property Sets or returns a Boolean value that indicates if a pattern search is case-sensitive or not.
Length Property Returns the length of a match found in a search string.
Number Property Returns or sets a numeric value specifying an error.
Pattern Property Sets or returns the regular expression pattern being searched for.
Source Property Returns or sets the name of the object or application that originally generated the error.
Value Property Returns the value or text of a match found in a search string.
Language Element
Description
Call Statement Transfers control to a Sub or Function procedure.
Class Statement Declares the name of a class.
Const Statement Declares constants for use in place of literal values.
Dim Statement Declares variables and allocates storage space.
Do...Loop Statement Repeats a block of statements while a condition is True or until a condition becomes True.
Erase Statement Reinitializes the elements of fixed-size arrays and deallocates dynamic-array storage space.
Execute Statement Executes one or more specified statements.
ExecuteGlobal Statement Executes one or more specified statements in the global namespace of a script.
Exit Statement Exits a block of Do...Loop, For...Next, Function, or Sub code.
For...Next Statement Repeats a group of statements a specified number of times.
For Each...Next Statement Repeats a group of statements for each element in an array or collection.
Function Statement Declares the name, arguments, and code that form the body of a Function procedure.
If...Then...Else Statement Conditionally executes a group of statements, depending on the value of an expression.
On Error Statement Enables error-handling.
Option Explicit Statement Forces explicit declaration of all variables in a script.
Private Statement Declares private variables and allocates storage space.
PropertyGet Statement Declares the name, arguments, and code that form the body of a Property procedure that gets (returns) the value of a property.
PropertyLet Statement Declares the name, arguments, and code that form the body of a Property procedure that assigns the value of a property.
PropertySet Statement Declares the name, arguments, and code that form the body of a Property procedure that sets a reference to an object.
Public Statement Declares public variables and allocates storage space.
Randomize Statement Initializes the random-number generator.
ReDim Statement Declares dynamic-array variables and allocates or reallocates storage space at procedure level.
Rem Statement Includes explanatory remarks in a program.
Select Case Statement Executes one of several groups of statements, depending on the value of an expression.
Set Statement Assigns an object reference to a variable or property.
Sub Statement Declares the name, arguments, and code that form the body of a Sub procedure.
While...Wend Statement Executes a series of statements as long as a given condition is True.
With Statement Executes a series of statements on a single object.


© 1999 Microsoft Corporation. All rights reserved.