Almost all programming languages have the functionality for adding comments. A comment is an explanatory and descriptive text used in the code. You can write in free text form inside the code without affecting the code's functionality.
How to add a commentIn Visual Basic, adding comments is very easy. You have to begin with an apostrophe (') and whatever you write after that becomes a comment. The comments are highlighted in green font in VB.
' This is a comment.
Why is it a good practice?Comments are an ideal way to document the any programming code. There are many ways of building a particular functionality inside a code and every programmer has his/her own style. To make the understanding of your code easier for others, it is always wise to comment your code.
You can almost write anything inside a comment; however, it would be good to include the following basic descriptions while commenting.
PurposeA few lines about what is the purpose of your code
Author Who wrote the code and when.
Version/ChangesA list of major updates and who made them
RequirementsSometimes, you may need to enable certain reference libraries or reference other modules. It would be a good idea to describe those requirements in your comments.
Apart from the above basic things, you can go to the extent of explaining even the variables, parameters, loops, error conditions and programming algorithms you have used in your code so that it makes your code more lucid.
Back to Visual Basic for Beginners