Results 1 to 3 of 3

Thread: When to put code in a form or module?

  1. #1

    Thread Starter
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330
    Hi,
    This may be a fairly basic question but most of my programs are formless. I'm now beginning to create programs with forms.

    Is there a rule-of-thumb when your code goes in the form or a seperate module?

    Thanks,
    Al.

  2. #2
    Junior Member
    Join Date
    Apr 1999
    Location
    Location Greece.
    Posts
    25
    General i write the code in a Module when i use the same code from other forms in the same program.

    I hope that helps you.

  3. #3
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305
    If you have only one form, it doesn't matter. When you write an application with more than one form, though, it becomes more efficient to put it in a module. Say, for example, you want to use a particular API in two different forms. Rather than define it twice as Private in both forms, simply putting it once as Public in the module saves lots of space in the end. Also, it is easier to manage all your code when you don't repeat it. If you have a group of code that you repeat over and over, make a sub in the module and call it whenever you need it from the form. Like if you want to do 1, 2, 3, a, b, and c in that order frequently throughout the program, put a sub in the module that says

    Public Sub DOTHIS()
    Do 1
    Do 2
    Do 3
    Do a
    Do b
    Do c
    End Sub

    and call it by just writing DOTHIS in your code. The whole idea is to save space by preventing repetition.

    bob

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