How to Add Comments in Visual Basic

Determine which type of comment you want to add., Choose detailed categories of use for your code comments., Choose a format for comments., Use an apostrophe to mark the beginning of your comments.

4 Steps 2 min read Medium

Step-by-Step Guide

  1. Step 1: Determine which type of comment you want to add.

    Programmers have several different main purposes for comments that determine the exact format and style of what will be included in the comment.

    Consider code module comments.

    Module comments are higher-level comments that usually describe the overall purposes of the code module, as well as other information like copyright, authorship and more.

    Assess the need for procedure comments.

    Various functional code procedures should also be commented.

    Procedure comments relate to the specific functions of code, and they help to alert other programmers about the exact results of a procedure according to how it is written.
  2. Step 2: Choose detailed categories of use for your code comments.

    Some types of comments, like procedure comments, also come in different forms.

    Understand these different uses in order to add the right kinds of comments to your program.

    Assess the use of purpose comments for procedures.

    These describe what the procedure does.

    Consider the use of function return value comments.

    These will help others to understand what values are returned by procedure.

    Include conditional comments.

    Conditional comments can describe possible error conditions and error handling, as well as conditions that must be met for code to work properly. , There's also the issue of how you will add comments to specific lines of code.

    Utilize left-handed comments.

    These comments start at the left of the screen and continue the whole way across a line.

    Commonly, the coder needs to arbitrarily end the comment near the right side of the screen, go down to a new line and continue the comment.

    Use in-line comments.

    In-line comments have an apostrophe directly after a piece of code and are placed on the same line. , This is the key step for actually writing comments into code.

    The apostrophe is the specific text protocol that the Visual Basic compiler recognizes for comments.

    Without this, the computer will try to read the comments as code.
  3. Step 3: Choose a format for comments.

  4. Step 4: Use an apostrophe to mark the beginning of your comments.

Detailed Guide

Programmers have several different main purposes for comments that determine the exact format and style of what will be included in the comment.

Consider code module comments.

Module comments are higher-level comments that usually describe the overall purposes of the code module, as well as other information like copyright, authorship and more.

Assess the need for procedure comments.

Various functional code procedures should also be commented.

Procedure comments relate to the specific functions of code, and they help to alert other programmers about the exact results of a procedure according to how it is written.

Some types of comments, like procedure comments, also come in different forms.

Understand these different uses in order to add the right kinds of comments to your program.

Assess the use of purpose comments for procedures.

These describe what the procedure does.

Consider the use of function return value comments.

These will help others to understand what values are returned by procedure.

Include conditional comments.

Conditional comments can describe possible error conditions and error handling, as well as conditions that must be met for code to work properly. , There's also the issue of how you will add comments to specific lines of code.

Utilize left-handed comments.

These comments start at the left of the screen and continue the whole way across a line.

Commonly, the coder needs to arbitrarily end the comment near the right side of the screen, go down to a new line and continue the comment.

Use in-line comments.

In-line comments have an apostrophe directly after a piece of code and are placed on the same line. , This is the key step for actually writing comments into code.

The apostrophe is the specific text protocol that the Visual Basic compiler recognizes for comments.

Without this, the computer will try to read the comments as code.

About the Author

J

Joan Bell

Enthusiastic about teaching home improvement techniques through clear, step-by-step guides.

50 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: