Results 1 to 4 of 4

Thread: [RESOLVED] Breaking code into managable pieces.

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2009

    Resolved [RESOLVED] Breaking code into managable pieces.

    I am working on a project and the code for FORMS1.vb has become quite large, 20K lines.
    How can I break this down into more managable pieces. I have tried Modules but I get multiple reference errorsd when I move like all of the reporting code to a module. The report code has nothing to do with the forms other than being able to call that code from an object on the form.
    Does a specific module need to be selected from the templates that would still be able to get global definitions from FORMS1.vb or how should I approach doing this. I have tried multiple senarios and none seem to work.
    I'm not creating new classes or anything like that just want to break my source code down into smaller chunck. Can this be done. Any reference points to look at for help?

    Thanks Rick

  2. #2
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Bay Area, CA

    Re: Breaking code into managable pieces.

    Hi Rick, it sounds like you're on the right track. A standard module should work just fine. You need to hunt down which references are broken when you move the code and import those references into the module. They shouldn't be hard to find as they are most likely framework refs sitting at the top of your form right now.

    Another thing to look at is how much of your code might be reusable? I know that when I'm coding I'm often focused on getting the job done rather then managing the beast it may become. There have been many times I've gone back to an old project, just to polish it up, and found that I could put a general function in the place of several routines.

    I'm not sure if you're familiar with Regions but they sure have been a nice code management tool to have around.

    I tend to put all of my form events in one Region, button events in another, menu events in another, and so on. That way I can just collapse all of the regions that I'm not currently working in. Once the subroutines have all been categorized, I'll often times alphabetize them.

    For example,
    #Region " Form Events "
            Private Sub Form_Closing
            Private Sub Form_Load
    #End Region
    Good luck, I hope this helps.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2009

    Re: Breaking code into managable pieces.

    Trying to put things into the "Code File" module and making the references back to the main form.
    The regions is interesting. Where are you coding that. Is it in a module by itself with all your routines defined where, in another module or in the same space as the regions?

    Again Thanks.

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005

    Re: Breaking code into managable pieces.

    What are your reference errors? Do you have stuff like TextBox1.Text in the module now? If so this is not possible in the module since there are no objects like that in the module. You would need to fully qualify the path i.e. Form1.TextBox1.Text or pass the value into the modules procedure a parameters.

    The region can be used anywhere. The example was on a forms module. You can use them in a code module also if you want.
    Sometimes the Programmer
    Sometimes the DBA


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width