Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block commenting VB/VB.NET code

Tags:

vb.net

vb6

People also ask

How do you write comments in VB net code?

In VB . NET, you write a comment by writing an apostrophe ' or writing REM . This means the rest of the line will not be taken into account by the compiler.

How do you comment multiple lines in VB net?

Write your chunk, select it and press Ctrl+K, Ctrl+C to comment it.

How do I block comment code?

The leading characters // are added to the beginning of each line when commenting one or more lines of code. You can also block comment multiple lines of code using the characters /* */ .


VB doesn't have such a construct at the language level. It has single line comments using apostrophe character:

' hello world
' this is a comment
Rem this is also a comment

However, Visual Studio has a functionality to automate this task. Select the lines you want and press Ctrl+K+C for commenting and Ctrl+K+U for uncommenting (General Development Settings shortcuts, look at the "Edit -> Advanced" menu while selecting some code to see the shortcuts).


Totally abusing compiler directives here... but:

#If False Then
Comments
go
here
#End If

You don't get the benefits of proper code coloration (it doesn't show in green when using the default color scheme) and the implicit line-continuation system automatically indents lines in a paragraph starting at the second line. But the compiler will ignore the text.


The other answers explain how to comment/uncomment automatically in VB.NET. Just for completeness, in VB6 use these toolbar buttons: alt text. More details here.


Here is a cludgy way to make a multiline comment which is also collapsible.

    If <![CDATA[ Multiline comment about this and that

Comment about this 
and that and so on
with lots of lines

    ]]> Is Nothing Then : End If

It looks like this when you collapse it

If <![CDATA[ Multiline comment about this and that ...  Is Nothing Then : End If