As you read the code examples, you often encounter the comment symbol ('). This symbol tells the Visual Basic compiler to ignore the text following it, or the comment. Comments are brief explanatory notes added to code for the benefit of those reading it.
It is good programming practice to begin all procedures with a brief comment describing the functional characteristics of the procedure (what it does). This is for your own benefit and the benefit of anyone else who examines the code. You should separate the implementation details (how the procedure does it) from comments that describe the functional characteristics. When you include implementation details in the description, remember to update them when you update the function.
Comments can follow a statement on the same line, or occupy an entire line. Both are illustrated in the following code.
' This is a comment beginning at the left edge of the screen.text1.Text = "Hi!" ' This is an inline comment.
If your comment requires more than one line, use the comment symbol on each line, as the following example illustrates.
' This comment is too long to fit on a single line, so we break ' it into two lines. Some comments might need three or more lines.
The following table provides general guidelines for what types of comments can precede a section of code. These are suggestions; Visual Basic does not enforce rules for adding comments. Write what works best, both for you and for anyone else who reads your code.
Comment type
Comment description
Purpose
Describes what the procedure does (not how it does it)
Assumptions
Lists each external variable, control, open file, or other element accessed by the procedure
Effects
Lists each affected external variable, control, or file, and the effect it has (only if it is not obvious)
Every important variable declaration should be preceded by a comment describing the use of the variable being declared.
Variables, controls, and procedures should be named clearly enough that commenting is needed only for complex implementation details.
Comments cannot follow a line-continuation sequence on the same line.
You can add or remove comment symbols for a block of code by selecting one or more lines of code and choosing the Comment () and Uncomment () buttons on the Edit toolbar.
Note
You can also add comments to your code by preceding the text with the REM keyword. However, the ' symbol and the Comment/Uncomment buttons are easier to use and require less space and memory.
By using comment symbol ( ' ), we can comment on the code in our Visual Basic programming. The comment symbol ( ' ) will tell the Visual Basic compiler to ignore the text following it, or the comment.
To add a comment to your VBA macro code, simply type an apostrophe ( ' ) and start typing. All the remaining text in that code line will be considered a comment (non-executing code) and will typically turn a green color once you navigate to the next line.
The single line comment is //. Everything from the // to the end of the line is a comment. To mark an entire region as a comment, use /* to start the comment and */ to end the comment.
For a multiple-line comment, repeat the comment symbol ( ' ) on each line. Although placing each statement on a separate line is the recommended method, Visual Basic also allows you to place multiple statements on the same line.
Use the built in functionality in Visual Studio under Edit -> Advanced -> Comment Selection. The functionality is also available as toolbar buttons on the "Text Editor" toolbar, or via keyboard shortcuts [Ctrl+K, Ctrl+C] to comment and [Ctrl+K, Ctrl+U] to uncomment.
To comment in React, you can use the syntax {/* */} . Anything you put between these two sets of curly braces will be treated as a comment and will not be executed by the JavaScript engine. Here's an example in action: https://codepen.io/shecodes/pen/dypYvXp.
In VBA, comments must adhere to a specific format whereby each line of comment must commence with a ' symbol followed by text. Unfortunately, there is no streamlined approach for composing multiline comments in VBA.
Line comments either start with a comment delimiter and continue until the end of the line, or in some cases, start at a specific column (character line offset) in the source code, and continue until the end of the line. Some programming languages employ both block and line comments with different comment delimiters.
Code commenting is the practice of sprinkling short, normally single-line notes throughout your code. These notes are called comments. They explain how your program works, and your intentions behind it. Notice how the comment on the first line describes the line of code below it.
A comment is something that you say which expresses your opinion of something or which gives an explanation of it. He made his comments at a news conference in Amsterdam. I was wondering whether you had any comments about that? There's been no comment so far from police about the allegations.
Unfortunately, you cannot block comment VBScript like you can in other languages. You can comment out each line individually. Just put a single quotation mark at the start of the line you want to 'out' and do then do the same for each subsequent line.
Hobby: Web surfing, Rafting, Dowsing, Stand-up comedy, Ghost hunting, Swimming, Amateur radio
Introduction: My name is Virgilio Hermann JD, I am a fine, gifted, beautiful, encouraging, kind, talented, zealous person who loves writing and wants to share my knowledge and understanding with you.
We notice you're using an ad blocker
Without advertising income, we can't keep making this site awesome for you.