How to Make Comments in VBS Code

Visual Basic Script code, like all programming source code, can be difficult to read and understand when left to speak on its own. Structured programming practices can improve on this somewhat, but ultimately, if a programmer wants to make sure that he will understand his own coding weeks or months later when the time comes to maintain it, he will need to use comments to explain what the code is attempting to do. Visual Basic Script supports two different comment commands. When it encounters one of these commands, Visual Basic Script assumes the rest of the line contains comments intended for the developer rather than programming code.

Begin a line within a Visual Basic Script document with “Rem” to add a basic comment, like so: Rem This is a comment.

The Rem command stands for “Remark,” and it has been around since the original BASIC programming language.

Use a single quote instead of Rem to save a few characters, instead: ‘ This is a comment as well.

Besides being faster to type, the single quote is also easier to read in multiline comments, as the below example illustrates:

Rem This is a

Rem multiline

Rem comment.

‘ This is a

‘ multiline

‘ comment.

Each of the above sets of comments is valid, but it is easier to read the second set of comments than the first.

Use either “Rem” or a single quote at the end of a line, instead. To use “Rem,” type a colon and space first:

Document write(“This is printed to the screen”) : Rem This is a comment.

Or, use the single quote with nothing separating it from the code:

Document write(“This is printed to the screen”) ‘ This is also a comment.

By inserting “: Rem” or simply a single-quote mark, you’re instructing Visual Basic Script to ignore the rest of line, leaving you free to write comments.

Leave a comment