Click here to Skip to main content
15,917,062 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to comment code in Visual Studio 2019-VB.Net

What I have tried:

This may be a dumb question, but I have searched for an answer to.. to comment a line of code I use the apostrophe code '. I've seen examples codes use the slash code /. When I use this I get a syntax error using Visual Studio 2019. Which is the correct way to make comments?
Updated 6-Feb-20 8:36am
Richard MacCutchan 6-Feb-20 3:53am    
Comment styles are defined by the language in use (VB, C, C#, Java ...), not the IDE (Visula Studio).

To comment single line, use ['] (apostrophe).

Other option is:
CTRL + K then CTRL + C - to comment selected line(s)
CTRL + K then CTRL + U - to uncomment selected line(s)
Share this answer
To add to what Maciej says: for VB, ' is the comment indicator, but very few languages use that - many use either /* or // to indicate a quote (and for Intellisense / XML comments in C# you use three: ///)

You can do the same in VB with three quotes: '''
This allows you to add documentation to your methods, fields, and properties which will be picked up by Intellisense and shown whe you start using them.
Share this answer
MadMyche 5-Feb-20 17:09pm    
<!-- HTML Comment -->

-- SQL one-line comment
Visual studio 2019 comment syntax

The syntax of comments is not linked to IDE (visual studio), but is linked to programming language.
For VBA or VB.Net
' This is a comment because of the ' at beginning.
A=1 ' and this is usually to comment the reason of the line of code
' so next is commented
' A=1
Share this answer
Thanks all for your replies. However, I have tried all your suggestions..CTRL + K then CTRL + U, one / , 2 //, etc....still getting syntax error. I've checked Options under TOOLS and nothing jumps out at me.

I guess I'll continue use the apostrophe. '
. It just bugs me :-)
Share this answer
Richard MacCutchan 6-Feb-20 14:27pm    
Visual Basic comments are started by the apostrophe character. Anything else is considered to be code and will be passed through to the compiler. And in the case of /, // etc will be thrown out as syntax errors. If you do not like this construct you can always switch to C, C++, C# etc.
Member 1753250 6-Feb-20 14:45pm    
Thanks for the quick reply Richard. So, my program must be Visual Basic? One more dumb can I tell and how to switch to C, C+, C#. Any advantages doing this?
Dave Kreskowiak 6-Feb-20 15:20pm    
You have to create a new project from scratch. There's no way easy way to convert an existing project from one language to another.
Richard MacCutchan 7-Feb-20 3:43am    
If you do not know which language you are coding in then you are going to have some major problems. I suggest you do some reading and decide first which one will suit your requirements.
Maciej Los 6-Feb-20 14:34pm    
This is not an answer. Please, delete it to avoid downvoting.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900