The Microsoft Visual Basic computer programming language has been popular in programming circles for many years. Programmers use it for all sorts of projects. Variants of this programming language are used for web pages, and other types of Visual Basic programs are used for many of the Windows applications that we use every day. One of the essential elements of Visual Basic is the ability to include comments, which are notes embedded into the code that do not have a functional code purpose. Visual Basic uses specific protocol to distinguish these from code. Adding comments is extremely important in most projects to help human code viewers read the code modules correctly. If you need to add comments to Visual Basic, here are some of the fundamental steps to making sure that you do this correctly.

Steps

  1. 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. 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.
    Advertisement
  3. 3
    Choose a format for comments. 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.
  4. 4
    Use an apostrophe to mark the beginning of your comments. 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.
  5. Advertisement

Community Q&A

  • Question
    What is the reason fo coding in Visual Basic?
    Community Answer
    Community Answer
    Visual Basic can be used to make simple scripts in Windows as well as full-fledged apps. It can also be used for macros in Microsoft Office (little programs that run in a document).
  • Question
    Explain how comments are written in Visual Basic using examples
    Community Answer
    Community Answer
    In Visual Basic, comments start with a single quote ( ' ) anything after the single quote will be ignored until the next line. These types of comments are single line comments. Example: ' This is a very good comment but this will not be ignored since it is on the next line ' to fix that, add a single quote in front of each line of your comments
Advertisement

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 9 people, some anonymous, worked to edit and improve it over time. This article has been viewed 55,179 times.
How helpful is this?
Co-authors: 9
Updated: November 16, 2021
Views: 55,179
Categories: Programming
Advertisement