General Add-ons Plug-ins Scripting Syntax Files Dictionaries (External)
VBScript Reference
Language Overview
VBScript is a natively implemented Basic-like scripting language that is untyped, Variant-based, and dynamic, supporting procedures (Subs), functions, variable declarations, and global statements, with exception handling using throw/try/catch/finally.
Besides classic VB tokens like Dim, Call, and Set, the syntax includes modern VB.NET-style constructs such as Return, New, and TypeOf/Is, while all variables and parameters are Variants supporting numbers, strings, Booleans, dates, IDispatch objects, and special values Null, Empty, Nothing, True, and False.
Line breaks are significant like in classic Basic, though multiple short statements can share a line using a colon ":"; square-bracket identifiers permit spaces and symbols, useful when interfacing with imported object models.
Global declarations
Global statements can appear anywhere in a unit, even between Sub/Function declarations, and are executed at activation time; declarations define Subs, Functions, and variables with Dim, with optional initializers.
' Variables and routines
Dim X, Y
Dim Z : Z = 7
Sub P(A, B)
Dim i, j
Dim k : k = 3
ShowMessage A + B + F * 3.14
End Sub
Function F()
F = 7
End Function
' Global statement
ShowMessage "This is a global statement"
Order is flexible: routines and variables may reference each other; Exit exits a routine, and parameters are by value unless semantics specify otherwise for ByRef patterns in host interop.
Conditional Statements (If, Select/Case)
If
If/Then conditionally executes statements; blocks may be a single statement per line or multiple statements when separated by colons or explicit line breaks.
If > 0 Then ShowMessage "X is positive"
If S <> "" Then
ShowMessage "S is not empty"
Else
ShowMessage "S is empty"
End If
Select Case
Select Case supports multiple labels per case and an optional Case Else; labels can be strings, numbers, or ranges to simplify multi-branch dispatch.
Select Case x
Case 0: ShowMessage "Zero"
Case 1, 3, 5, 7, 9: ShowMessage "Odd"
Case 2, 4, 6, 8, 10: ShowMessage "Even"
Case Else: ShowMessage "Too big"
End Select
Loop Statements (For, Do)
For loops iterate over a numeric range; Do While/Loop checks the condition pre- or post-body; Exit exits the current Sub/Function while Continue-like behavior is expressed via control flow patterns.
Dim i
For i = 0 To 10
ShowMessage i
Next
i = 1
Do While i < 10
ShowMessage i
i = i * 2
Loop
i = 1
Do
ShowMessage i
i = i * 2
Loop Until i >= 10
Exception Handling Statements (Throw, Try)
Throw
Throw raises an exception object produced by an expression like Exception.Create, assuming availability of the corresponding Delphi exception class in the host environment.
If X > 10 Then
Throw Exception.Create("X is too big")
End If
Try/Catch/Finally
Try/Catch supports typed catches (On E As T) and a general catch pattern, with Finally ensuring cleanup; rethrow uses a bare Throw within a Catch block.
Try
DoSomething
Catch
ShowMessage "Error has occurred."
End Try
Try
DoSomething
Catch E As EArgumentException
ShowMessage "Invalid argument"
Catch E As EOutOfMemory
ShowMessage "Out of memory"
Finally
Cleanup
End Try
Expressions
Expressions include assignment, calls, property access, arithmetic, logical operators, and literals (numbers, strings, Null/Empty/Nothing/True/False), with support for concatenation and operator precedence.
x = 7: x = -7: x = 7.0
s = "Some string"
s = "This is a string with a quote "" inside"
s = "Line1" & vbCrLf & "Line2"
' Calls & properties
P 5, 7
x = F(3)
s = Application.ActiveForm.Caption
Arrays
VBScript supports single and multi-dimensional arrays; use parentheses in Dim for bounds, default lower bounds apply, and Length/Low/High mirror the host's helpers conceptually.
Dim a(7) ' 0..7
Dim b(0 To 5) ' explicit bounds
Dim m(0 To 7, 1 To 3)
Intrinsic Functions
Special branching functions
ExitBreakContinue
Constants
NullEmptyNothingTrueFalse
Functions
AbsArcTanCosSinLnExpSqrSqrtRoundTruncIntFracRandomOddCompareStrCompareTextAnsiCompareStrAnsiCompareTextAnsiLowerCaseAnsiUpperCaseLowerCaseUpperCaseTrimTrimLeftTrimRightCopyDeleteInsertPosIsValidIdentVarIsNullIntToStrIntToHexFloatToStrVarToStrFormatFormatFloatFormatDateTimeDateTimeNowDateToStrTimeToStrDateTimeToStrStrToDateStrToTimeStrToDateTimeDecodeDateDecodeTimeEncodeDateEncodeTimeDayOfWeekIsLeapYearIncMonthStrToFloatStrToIntStrToIntDefIncludeExcludeHighLowLengthOrdAssignedIncDecChrShowMessageInputQueryBeepCreateOleObjectGetActiveOleObject
BNF Syntax
The grammar summary outlines units, declarations, statements, expressions, arrays, and operators accepted by VBScript, reflecting its Basic-style syntax and precedence.
<Unit> ::= {<GlobalStmt> | <SubDecl> | <FuncDecl>}
<GlobalStmt> ::= <Statement> NEWLINE
<SubDecl> ::= Sub <Identifier> NEWLINE <StmtBlock> End Sub
<FuncDecl> ::= Function <Identifier> NEWLINE <StmtBlock> End Function
<Params> ::= <Identifier> {"," <Identifier>}
<StmtBlock> ::= {<Statement> NEWLINE}
<Statement> ::= <Assignment> | <Call> | <IfStmt> | <SelectStmt> | <ForStmt> | <DoStmt> | <TryStmt> | <ThrowStmt>
<Assignment> ::= <Designator> "=" <Expression>
<IfStmt> ::= If <Expression> Then <StmtBlock> End If
<SelectStmt> ::= Select Case <Expression> NEWLINE {Case <CaseLabelList> ":" <StmtBlock>} End Select
<ForStmt> ::= For <Identifier> "=" <Expression> To <Expression> NEWLINE <StmtBlock> Next
<DoStmt> ::= Do NEWLINE <StmtBlock> Loop
<TryStmt> ::= Try NEWLINE <StmtBlock> {Catch NEWLINE <StmtBlock>} End Try
<ThrowStmt> ::= Throw <Expression>
<Expression> ::= ... ; literals, calls, properties, operators
<ArrayDecl> ::= Dim <Identifier> "(" <Bounds> {"," <Bounds>} ")"
<Bounds> ::= INT | INT To INT
