Tool to reformat VB.Net code - specifically line breaks
Question
Are there any tools available for automatically formatting vb.net code - specifically for adding line breaks at a predefined line length? I'm working with a lot of code with long lines (thousands of lines), and manually reformatting it is quite time consuming. I've seen a number of tools for rearranging code into regions etc., but haven't found any that reformat with line breaks. Free would be great.
Solution
Try having VS auto-wrap your lines. The option should be in the Tools | Options | Basic | Settings | Word Wrap.
Another thing to do is go to the Edit | Advanced | Format Document menu option, which helps clear the air with not well-formed documents.
A 3rd option is to install DevExpress' Code Rush Xpress add-on, which add's very handy vertical lines for when code blocks begin and end, and also helps in refactoring code. You can get it from here: http://devexpress.com/Products/Visual_Studio_Add-in/CodeRushX/. It's free, but doesn't support the Express editions of Visual Studio.
OTHER TIPS
Use Visual Studio 2008 you have to use Ctrl + A + K + F for formatting your c#, vb code
I know this was posted a long time ago. But if ever someone had the same problem, try this sub I made. The sub will have two outputs (Textbox1 = Code with breaks, Textbox3 = a one liner code).
Create two textboxes (named Textbox1 and Textbox3) and a button (Button1)
Create a sub (name what you want) and enter this code:
Try
Dim x As String = TextBox1.Text
x = x.Replace("& """, "")
x = x.Replace(""" _", "")
x = x.Replace("""", "")
x = x.Replace(vbNewLine, "")
x = x.Replace(vbTab, "")
While x.Contains(" ") '2 spaces.
x = x.Replace(" ", " ") 'Replace with 1 space.
End While
TextBox3.Text = x
Dim l As Integer = Len(x)
Dim xlim As Integer = InputBox("Specify the maximum number of characters for each line:", "Line Max", 66)
Dim ylim As Double = 0
TextBox1.Text = ""
ylim = l / xlim
If Int(ylim) <> ylim Then
ylim = Int(ylim) + 1
Else
ylim = Int(ylim)
End If
Dim una As String = "", huli As String = ""
Dim mynewstring As String = ""
Dim startin As Integer = 1
For i = 1 To ylim
If i = 1 Then
una = """"
Else
una = vbTab & "& """
End If
If i = ylim Then
huli = """"
Else
huli = """ _"
End If
mynewstring = mynewstring & una & Strings.Mid(x, startin, xlim) & huli & vbNewLine
startin += xlim
Next
TextBox1.Text = mynewstring
Catch ex As Exception
MsgBox(ex.Message)
End Try
P.S. I did not add the code to restore your original input.