|
-
Oct 26th, 2005, 02:42 PM
#1
Thread Starter
New Member
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
-
Oct 26th, 2005, 02:50 PM
#2
PowerPoster
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.
-
Oct 26th, 2005, 03:18 PM
#3
Fanatic Member
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.
-
Oct 26th, 2005, 03:53 PM
#4
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.
-
Oct 26th, 2005, 06:11 PM
#5
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.
-
Oct 26th, 2005, 07:14 PM
#6
Re: Forms VS Modules
 Originally Posted by Pasvorto
...I guess, by today's standards, Global Variables should be put in the same archive as GOTOs.
Not necessary - there could be plenty of reasons to have publics vars/properteis/subs/functions...
-
Oct 26th, 2005, 07:17 PM
#7
Re: Forms VS Modules
 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.
-
Oct 26th, 2005, 07:21 PM
#8
Re: Forms VS Modules
 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.
-
Oct 26th, 2005, 07:44 PM
#9
Re: Forms VS Modules
 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?
-
Oct 26th, 2005, 08:04 PM
#10
-
Oct 27th, 2005, 05:36 AM
#11
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.
-
Oct 27th, 2005, 07:14 AM
#12
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|