Results 1 to 12 of 12

Thread: Forms VS Modules

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Location
    Minnesota
    Posts
    6

    Forms VS Modules

    I am a untrained hacker that has learned just enough to be dangerous to myself. I have a program that has evolved over the last few months that keeps getting bigger. As time progressed I learned new things and you can really see it in my oldest code (but it works ). I have several forms and modules. The main reason for this is I wanted to use them both.
    Now my question - If I am not declaring any global variables should I just be putting all my code on the form I am working with or should I be using a module for the bulk of the code? Does it matter?
    For instance I have a main form that calls a subform that performs a service. Some of the routines are on the subform but I have some in a module.
    If I was to quit and you had to take my place and maintain it what would an experienced programmer want to see?
    TIA

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Forms VS Modules

    Well, if you have data on one form that needs to be on another form...

    If form A is unloading then I would have a PUBLIC variable declared in a module. Dat is moved from Form A to the variable and from the variable to Form B.

    If Form A is not unloading I would reference the field in Form B (FormA.textfield.text)

    I guess, by today's standards, Global Variables should be put in the same archive as GOTOs.

  3. #3
    Fanatic Member neicedover1982's Avatar
    Join Date
    Jun 2005
    Posts
    566

    Re: Forms VS Modules

    I usually put big functions into the modules and leave the code on my forms clean. In one of my games I am calculating poker hands, and that function is in a module so I only use 1 line of code in my form. Since I have about 5 functions dealing with the cards I put them all in a module call "mdlCardFunctions"

    I guess using modules is up to the person but I like them since I can bulk specific functions dealing with 1 topic together.
    Kevin | New England Iced Over | http://www.kevincawleyjr.com

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Forms VS Modules

    mcoonrod,

    Generally you want to put in a module, code that can be used by other forms and modules. This allows your code base to be smaller and reusable.

  5. #5
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Forms VS Modules

    A form is technically worked with like a class module. So there are some limitations when working with forms. Also, code in modules is executed faster than code in a Form as well as a class module. I proved it in a performance test a while back. You should get into the habit of using modules at a regular basis. It helps organize your code, and you won't be cramming all of your code in one form.

  6. #6

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Forms VS Modules

    Quote Originally Posted by Jacob Roman
    A form is technically worked with like a class module. So there are some limitations when working with forms. Also, code in modules is executed faster than code in a Form as well as a class module. I proved it in a performance test a while back. You should get into the habit of using modules at a regular basis. It helps organize your code, and you won't be cramming all of your code in one form.
    I would almost completely disagree - "moving" code from form to module would require some of your declarations/subs/functions to be public which in turn may create some issue(s). I would agree if you'd say something like "I prefer ...", though.

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Forms VS Modules

    Quote Originally Posted by randem
    mcoonrod,

    Generally you want to put in a module, code that can be used by other forms and modules. This allows your code base to be smaller and reusable.
    Totally agree - standard modules are code repository and primarily serve one purpose: downsize your code by making some of your functionaly common. There are cases, however, when certain things cannot be done without general module - subclassing for instance.

  9. #9
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Forms VS Modules

    Quote Originally Posted by RhinoBull
    I would almost completely disagree - "moving" code from form to module would require some of your declarations/subs/functions to be public which in turn may create some issue(s). I would agree if you'd say something like "I prefer ...", though.
    Well of course there are many places in his code he would have to fix in order for it to move ok in his current project, but after making new projects, it doesn't become an issue when he actually starts working with modules. And I did mean "I prefer" without actually saying it.

    You should and I prefer mean the same thing, right?

  10. #10

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Forms VS Modules

    I have a general rule of thumb:

    If the sub/function is going to be used no where in the entire project except on one form, then I make the sub/function Private and put it on the form itself.

    If the sub/function is going to be/can be used on more than one form, it goes into a module.

    Few things make me crazier than seeing a variable declared, or a sub/function placed in a module and said variable or sub/function used once, on one form.

    Converserly, it makes me even crazier to see the same variable declared Private on ten different forms.

    IMO - where something goes depends on its need/use within your project.

  12. #12

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Location
    Minnesota
    Posts
    6

    Re: Forms VS Modules

    Thanks all!
    It helps me see where I can make some improvements in my project and maybe make my next one a little less confusing.

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