Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Function vs. Subroutine

Discussion in 'Information Technology' started by PeterM, Nov 8, 2005.

  1. PeterM

    PeterM
    Expand Collapse
    Guest

    Is it better for performance to have a set of code that is called from all
    forms be created in a module as a function or subroutine? Every one of our
    100+ forms calls this code to set the forecolor, backcolor, etc appearance
    for each form.

    Thanks in advance for your help!
     
  2. Loading...


  3. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    I don't think there'll be a noticable difference between the two.

    If you create a function (even if you don't have the function return a
    value), you can set the form's Open property to the name of the function,
    rather than having to have a Sub Form_Open for the form. On the other hand,
    I never do that...

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "PeterM" <PeterM@discussions.microsoft.com> wrote in message
    news:3C6E4DFF-AD16-4F9B-BE3C-12E4422A046F@microsoft.com...
    > Is it better for performance to have a set of code that is called from all
    > forms be created in a module as a function or subroutine? Every one of

    our
    > 100+ forms calls this code to set the forecolor, backcolor, etc appearance
    > for each form.
    >
    > Thanks in advance for your help!
     
  4. John Vinson

    John Vinson
    Expand Collapse
    Guest

    On Mon, 7 Nov 2005 08:06:05 -0800, PeterM
    <PeterM@discussions.microsoft.com> wrote:

    >Is it better for performance to have a set of code that is called from all
    >forms be created in a module as a function or subroutine? Every one of our
    >100+ forms calls this code to set the forecolor, backcolor, etc appearance
    >for each form.
    >
    >Thanks in advance for your help!


    Performance of a Sub or a Function should make very little if any
    difference. However, a Function is handy in one way - you don't need
    to actually create an [Event Procedure] in each form to call it.
    Instead simply put

    =MyFunction([Form])

    on the form's Open (or other appropriate) event; within the function,
    use

    Public Function MyFunction(frm as Form)

    to pass the identity of the form as an argument.

    Obviously if you already have an Event Procedure, you can simply call
    the function within that procedure.

    John W. Vinson[MVP]
     
  5. Ron Hinds

    Ron Hinds
    Expand Collapse
    Guest

    "PeterM" <PeterM@discussions.microsoft.com> wrote in message
    news:3C6E4DFF-AD16-4F9B-BE3C-12E4422A046F@microsoft.com...
    > Is it better for performance to have a set of code that is called from all
    > forms be created in a module as a function or subroutine? Every one of

    our
    > 100+ forms calls this code to set the forecolor, backcolor, etc appearance
    > for each form.
    >
    > Thanks in advance for your help!


    More important than performance in this case is maintainability. If there is
    a bug in the function, right now you have to make the fix (*if* you remember
    to ;-) in 100+ forms, vs. ONCE if it is modularized!
     

Share This Page