Formatting source code RRS feed

  • Question

  • Help! I'm getting very frustrated getting my source code in VB.NET to format and stay formatted the way I'd like.

    In VB6, I used a code indenter, and I could set the options exactly as I wished. I manually wrapped long lines so they all viewed within the code window as I had sized it in the IDE.

    Now in VB.NET, when it upgraded my VB6 source, it threw away all of my manually split lines, so many of my lines overflow to the right of the code window. I've tried experimenting with the settings I've found under Tools > Options, but nothing comes close to giving me what I want. For example, I'd like each level of indenting to be two spaces, not four.

    It used to be that when I clicked in the white space to the right of a line of code, the cursor would automatically snap to the end of the line. Now it stays where I click, as though the line is padded with a number of spaces on the right end of the line.

    I like to put the parameters for a sub or function on separate lines, one per line, but now when I split the statement into multiple lines and try to line up all the lines besides the first, it aligns them where it wants, not where I tabbed them to be.

    Does anyone have any suggestions for how I can better format my code so I don't have to waste a lot of time scrolling around and not actually writing and debugging code? Thanks in advance!

    Friday, June 15, 2007 9:25 PM


All replies

  • DRM55,


    As a side note, it is worth mentioning Outlining. Outlining is a tool for organizing code into a more readable format. Highlight a portion of code, then right-click and select the Outlining submenu. Hide Selection will collapse the marked selection of code and put an indicator (+ . . .) to be used to expand it again as needed. Also the hidden code can be quickly viewed without expanding by simply performing a mouse-over of the collapsed code indicator.


    Outlining and Hiding Code




    There are several articles that cover all the aspects for upgrading issue. I hope you are able to get some idea from the articles below:


    Upgrading Applications Created in Previous Versions of Visual Basic



    In this Section:


    Why Upgrading is Necessary

    Discusses the differences between Visual Basic 6.0 and Visual Basic .NET.

    Things to Consider Before Upgrading

    Discusses the limitations of and considerations for upgrading.

    Preparing a Visual Basic 6.0 Application for Upgrading

    Describes how to make sure that your application is ready to be upgraded.

    Language Recommendations for Upgrading

    Provides recommendations you can follow when preparing a Visual Basic 6.0 application for upgrade, or when developing Visual Basic 6.0 applications that might later be upgraded.

    Visual Basic 6.0 Compatibility Library

    Describes a mechanism provided for backward compatibility.

    Visual Basic Upgrade Wizard

    Provides an overview of upgrading a Visual Basic 6.0 project to Visual Basic .NET with the Upgrade Wizard.

    Upgrading a Project with the Upgrade Wizard

    Describes how to use the Upgrade Wizard.

    Upgrading Visual Basic 6.0 Code with the Upgrade Visual Basic 6 Code Dialog Box

    Explains how to upgrade Visual Basic 6.0 code to Visual Basic .NET code.

    Visual Basic 6.0 Code Upgrade Dialog Box

    Describes the user interface for upgrading Visual Basic 6.0 code to Visual Basic .NET code.

    Upgrading WebClass Projects to Visual Basic .NET

    Explains how to upgrade WebClass projects (also known as IIS Applications) to ASP.NET Web Application projects.

    Completing the Upgrading Process

    Describes what to do next after the Upgrade Wizard has finished running.

    Visual Basic Upgrade Report

    Describes the format and purpose of the Upgrade Report.

    Viewing the Upgrade Report

    Explains how to open the upgrade report.

    Upgrading a Project from the Command Line

    Describes how to use the command-line upgrading tool.

    Troubleshooting Applications Upgraded from Visual Basic 6.0

    Lists some known issues that are not detected by the upgrading tools and explains how to address them.





    Tuesday, June 19, 2007 7:01 AM
  • I'm sorry, but you must have misunderstood my questions. I don't have questions about the upgrading process. My questions concern formatting VB.NET source code. I don't want to repeat what I already described, so please reread my original message and let me know if there is anything in VB.NET or in an add-in (if such exist) to format my source code in a more readable (to me) format.

    Thank you!

    Wednesday, June 20, 2007 7:29 PM
  • Hi Dan,


    Have you looked into the settings "Tool" | "Options" then "Text Editor" => "Basic"?


    Here we at least should have  the setting for indent size (under "Tabs") and we can turn "Intending" to "Block" if you need more customization.


    There are also some settings under "VB Specific" that may help (hopefully).


    I also did not see the problem below as you mentioned:


    It used to be that when I clicked in the white space to the right of a line of code, the cursor would automatically snap to the end of the line. Now it stays where I click, as though the line is padded with a number of spaces on the right end of the line.


    If you create a new VB.Net project, does it have the same problem? Would it help with the current document that we select all and use the menu command "Edit" | "Advanced" | "Format Document"?


    Thursday, June 21, 2007 12:05 PM
  • Thank you! Your comments were very helpful.

    The white space issue that I mentioned was caused by the "Enable virtual space" option under the Text Editor > Basic > General options. When I uncheck this option, I get the snapping to the end of the line behavior that I wish.

    Again, thanks for your help!

    Thursday, June 21, 2007 7:28 PM
  • I am glad it helps.


    Enjoy posting in the forum Smile

    Monday, June 25, 2007 2:06 AM