Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Procedures, in Forms or Mods?

Status
Not open for further replies.

Iliemoo

Programmer
Sep 25, 2002
64
0
0
CA
Hi all, I've been involved with VB for quite a while and made a few not so complicated programs. However I always have a hard time deciding whether to include a procedure within a form or in a module. I am sort of uncomfortable when there are 5 procedures that are called UpdatePhoneNumber() in 5 different forms. However, they all run a little differently. On the other hand, trying to have common procedures usually results in a more complicated code and a longer list of parameters. What are your thoughts on this?
 
A form is an object, and if the procedure is included within the form, then it's becomes a method of that object. If the routine only applies to a specific form, (or object), which it seems to in your case, then I would make that a routine a method of that form (object), and put the routine in the form.

If on the other hand, the routine is global by nature, that being, it does not correspond to any particular object, then I wouldn't want it to be a method of any particular object, thus I would put it in a module.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I could see your problem with making your code work in a number of different situations, might get complicated, etc. I also agree with CajunCenturion that if your code relates only to that form, you should just keep it in that form. The one thought that I had though is that if you have a number of different UpdatePhoneNumber() procedures, then you might have only a part of those procedures that is common. If so, you should put that common part in a module then call it from each procedure in the forms once you have done the unique part.

Hope that helps!
 
I see it more as an issue of personal style. While the discussion of replicated code (and the implied maintenance issue) is quite valid, my preference is to generally abstract most 'code' to a general module and call the functions from VERY brief code in the form modules -even when the procedure is only used in the single form.




MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top