Visual Basic and Visual FoxPro comments


' or Rem


*, && or Note

Visual Basic Syntax Notes

VBA still recognises REM which has been used to mark comments since the first days of BASIC but this is rarely used in new work. The more common symbol in Visual Basic is the single quote to mark the start of a comment. This can be at the start of the line of code or anywhere within that line:

[VBA button for a block comment] ' A comment on its own line
a = b + c    ' A comment in another line

In both cases the comment runs from the quote to the end of the line.

There is no syntax in Visual Basic to mark the beginning and end of a multi-line comment. If you do need to comment out a block of code then highlight that code and use the Comment Block button on the Edit toolbar. This will add a single quote ' to the start of each line. Highlight the lines and click the Uncomment Block button to remove the comments.

Note that these two buttons might not be visible on your toolbar. If they are not there then right-click and select Customise to add them to the toolbar.

Visual FoxPro Syntax Notes

FoxPro shows its age as much as Visual Basic because it still recognises the NOTE marker from dBase II to mark a line as a comment. As with the VB REM comment, this is very old-fashioned syntax that is not used in new work.

[VBA button for a block comment] Visual FoxPro uses two different markers for a comment that is a line of its own and for a comment that is part of a program line. These markers are the asterisk * and the double ampersand &&:

* A comment on its own line
a = b + c    && A comment in another line

Like Visual Basic, Visual FoxPro does not have markers for the start and end of a block of comments. The technique here is to highlight the lines to be commented, right-click and then select Comment to mark a block comment or Uncomment to clear it. Fox marks each line with a special *!* combination and it will only clear comments which start with these characters. It will not clear your own comments.

This screenshot shows a block of SQL which has been commented out with the special *!* symbols but also shows some comments starting with *--. This is purely a personal habit. I mark my comments like this so that I can identify my own comments when I'm sharing the development work.

Arrays  |  Language index  |  Constants