Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put comments on each line in VB.NET?

Tags:

.net

vb.net

I used to be a C# developer so this commenting style was very easy in C#. This is driving me crazy but how do you do this in VB.NET without getting a syntax error?:

Private ReadOnly Property AcceptableDataFormat(ByVal e As System.Windows.Forms.DragEventArgs) As Boolean
    Get
        Return e.Data.GetDataPresent(DataFormats.FileDrop) _          'this is a file that a user might manipulate
                OrElse e.Data.GetDataPresent("FileGroupDescriptor")   'this is a typical Outlook attachment
    End Get
End Property
like image 651
Denis Avatar asked Mar 02 '12 16:03

Denis


People also ask

How do you comment multiple lines in VB net?

You can use Ctrl+K, Ctrl+C and Ctrl+K, Ctrl+U to comment or uncomment selected lines of text.

How do you write comment line in VB net code?

In Visual Studio . NET you can do Ctrl + K then C to comment, Crtl + K then U to uncomment a block.

How do you comment over multiple lines?

Press Ctrl + / To comment more than one line: Select all the lines that you would like to be commented.


3 Answers

Unfortunately you can't. VB.Net doesn't allow comments to appear in the middle of statements which span multiple lines (including both explicit and implicit line continuations). The comments must go above the statement or on it's final line.

The exception to this rule is statement lambdas. It is fine for comments to appear within a statement lambda even though it's technically one statement.

like image 125
JaredPar Avatar answered Oct 28 '22 04:10

JaredPar


Remove that comment from the line continuation and it should be fine. Comments cannot be used with the line continuation. The line continuation has to be the last character on the line so your comment cannot appear after it.

Here is a similar question: Why must VB.Net line continuation character be the last one on line

So like this:

 Private ReadOnly Property AcceptableDataFormat(ByVal e As System.Windows.Forms.DragEventArgs) As Boolean
        Get
            'Return a file that a user has dragged from the file system 
            'or a typical Outlook attachment
            Return e.Data.GetDataPresent(DataFormats.FileDrop) OrElse   
                   e.Data.GetDataPresent("FileGroupDescriptor")         

        End Get
    End Property

This is a limitation that has been bothering VB developers for a long time.

like image 34
jzworkman Avatar answered Oct 28 '22 04:10

jzworkman


Apparently this is now possible in Visual Studio 2017

Public Function foobarbaz(ByVal foo As Integer,   '' qux
                          ByVal bar As String,    '' quux
                          ByVal baz As DateTime)  '' garply

  Return foo.ToString &         '' Concatenate foo
         bar &                  '' with bar
         baz.ToString           '' and baz

End Function
like image 29
Ron DeFulio Avatar answered Oct 28 '22 02:10

Ron DeFulio