39

Do we have a multi line comment in VB.net.
I know in Java we have /* */ but that doesn't seem to work here.

2
  • This is also a duplicate: stackoverflow.com/questions/1909447/… Please first use the search before asking the same question.
    – JonH
    Commented Feb 22, 2011 at 20:17
  • there is .. see below my answer
    – Hichem
    Commented Aug 1, 2021 at 12:04

6 Answers 6

52

No we dont unfortunately..........

You can do: Ctrl + K, Crtl + C

To uncomment ctrl+k ctrl+u

3
  • @krum_cho highlight what you want to comment and then ctrl +k and ctrl+c to comment. No other way around it.
    – JonH
    Commented Feb 22, 2011 at 20:05
  • 2
    What if I don't use VB Studio and use notepad ++ instead ? Commented Dec 8, 2013 at 7:01
  • If you don't use VBStudio, you will need to make a macro up in Notepad++ or manually comment out each line. Commented Nov 28, 2015 at 23:00
14

In Visual Basic .Net 2008 and 2010, I use the following C++ Workaround.

#If AFAC Then

#End if

For English speaking AFAC = "à effacer" = "to delete"

I already use #If COMMENT or #If TODO

The #if COMMENT then solution is more powerful than the C++/Java/C# /* text */ solution because it is possible to nest #if but not /* !!!

For more information see the following link

3
  • 4
    More generally, you should be able to do #If 0 Then ... #End if to comment things out. (And put any text after //).
    – user1837158
    Commented Nov 24, 2012 at 16:39
  • 6
    why complicate? just use #If False Then. Commented Aug 27, 2015 at 15:56
  • 2
    I tried the #if approach, (VB.Net 2017). The problem is intellisense still kicks in within the #if block and interferes with your typing. Commented Sep 12, 2018 at 11:59
6

Just hold "alt"+"shift" and move cursor up or down to select lines, and press " ' "

1
  • 2
    WHOA i had no idea you could do that! Commented Feb 20, 2019 at 0:14
3

you can do on all visual studio version ..

#Region "mycomment"
 'comment line1
 'comment line2
#End Region

you will be able to hide and show the entire block

enter image description here

2

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

But it doesn't always matter as often you use ''' in front of a method or property to describe it. Then it will automatically create the comments for you.

1

Only single-line comments are possible in VB, unlike C/C++ and it's derivatives (Java, JavaScript, C#, etc.). You can use the apostrophe " ' " or REM (remark) for comments like this:

Sub Main()  
    ' This is a comment  
    REM This is also a comment  
End Sub  

But there is no multi-line comment operator in VB, unless you count using the keyboard shortcuts like @JonH and @Tedd Hansen said.

1
  • Sorry, but the #if AFAC that I describe previously do the same thing that /* */.
    – schlebe
    Commented Dec 23, 2016 at 7:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.