Code lines too long

+2 Glenn Walker · December 22, 2014
I have lines of code that are getting way too long.  e.g.:

line of fake code:

This line of code is so long that it goes on and on and on and on and on and on and on and on and on and so forth and so on

What I would like to do is to be able to split the above line of fake code into two or more lines.  I have looked for a means of doing this, but have come up with nothing.  Does anyone know how that might be done in VB?

Post a Reply


Oldest  Newest  Rating
0 cloakme free · August 21, 2015"this is a line " & vbcrlf & _
& "this is another line" & vbcrlf _
& "another line here")
0 Jay Bennett · January 12, 2015
Whenever I have used VB (I'm assuming this is VB.NET with Visual Studio), I've known it is the _ simple. Used in exactly the same way as the & in the post above. I'm not sure if the above example works, but if it doesn't, try the underscore :)
0 Vincenzo Marcella · January 13, 2015
Although there is  no way to really fix lines of lengthy code, the best way to handle it would be the way josh montes handled it. You could maybe edit something in the IDE that changes the way it formats the code on your screen like in eclipse but I wouldnt know about VB
0 Steve Rogers · September 4, 2015
The underscore works to continue the line without running on and on.  makes it a lot more readable.

Cloakme free 's examples is the best one to model.  simply place a space followed by an underscore (wherever you want to break) and then go to the next line.  the compiler will take out the underscore and treat it all as if it was the same line of code.

good luck.
-1 josh montes · December 23, 2014
Hello Glenn.

Below is a very simple piece of code that prints a message when the user clicks a button.

Public Class

 Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
                     MessageBox.Show("This is a very easy way for you to split up" &
                                                     " your code onto a different line")
       End Sub
End Class

You want to pay attention to the section in blue. All you need to do is enclose the string and connection it with "&" and then continues onto a new line.

The output will be the same as if it was in one line.

Hope this helps :)
  • 1

Visual Basic


One of the first products to provide a graphical environment and a paint metaphor for developing user interfaces.

Bucky Roberts Administrator