Skip to content

Syntax

The simplest expression is a single value. This one returns the string Hello World!:

"Hello World!"

A useful one reads the dataset and calculates something. This returns the value of a line:

%Qty * %UnitPrice

Statements and lines

Write one statement to a line. A statement needs no terminator. There is no semicolon and no full stop at the end of a line.

Case does not matter. Dim, dim and DIM are the same keyword, and NetValue and netvalue are the same variable. Write whichever case reads best and stay consistent within an expression.

Indentation does not matter either. VBScript ignores spaces and tabs at the start of a line. Indent the body of an If or a For to show its shape.

Two statements on one line

A colon separates two statements written on the same line:

Dim Qty : Dim Price

One statement over several lines

A space and an underscore at the end of a line continue the statement onto the next one. A long calculation or a long piece of concatenation reads better broken up:

Dim Description
Description = %ItemCode & " - " & _
              %ItemName & " (" & _
              CStr(%Qty) & ")"
Description

The underscore is the last thing on the line. Anything after it is a syntax error, a comment included, and VBScript reports "Invalid character".

IMan reads a continued statement as one line when it decides which line holds the result. See the last line is the result.

Comments

A comment records why the expression does what it does. VBScript ignores everything from the comment marker to the end of the line.

An apostrophe starts a comment, either at the start of a line or after a statement:

' Suppress the line when the warehouse is the returns bay.
%WarehouseCode <> "RET"   ' RET holds customer returns awaiting inspection

Rem does the same thing at the start of a line:

Rem Suppress the line when the warehouse is the returns bay.

Do not end an expression with a comment

IMan assigns the result from the last line that is not blank, and a comment line counts as a line. IMan writes the assignment onto the front of the comment, and VBScript reports "Expected statement". Put the comment above the result line, or on the end of it.

Words an expression cannot use

A VBScript keyword cannot name a variable, and Dim Select fails with "Expected identifier". The type names are the most common mistake. VBScript reserves Type, Currency, Integer, Double and the rest of them without ever using them, and Dim Type fails like any other keyword. Name the variable for what it holds, as LineType or CurrencyCode.

IMan wraps every expression in a function of its own, and nothing that belongs outside a function will compile inside one. Option Explicit and a Function or Sub of your own all fail. Put a function of your own in Common Functions.

Dim Date compiles, and breaks Date()

A function's name is not reserved. Dim Date compiles, and the variable then hides the function of the same name. A later Date() in the same expression raises "Type mismatch". Dim Left breaks Left the same way. Name the variable for what it holds, as OrderDate or Prefix.

A field reference carries none of these restrictions. %Select and %[End] read fields called Select and End without trouble, because IMan replaces the reference with a variable name of its own before VBScript sees the line.