View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Declaring variables in Module vs. Public

There is no performance difference by splitting up one module into multiple
modules. There is no performance difference between having private vs public
declarations. Where the difference arises is in scope. I follow the rule that
you always keep the scope of a variable as small as possible. The wider you
make the scope the more difficult that it becomes to debug the value if
something goes wrong. Additionally I avoid having global or module wide
declarations with a passion. My current project has over 3,000 lines of code
and only 4 such declarations. In most circumstances global or module wide
declarations can be avoided by passing values from one procedure to the next.

When should you break code into seperate module. Whenever it makes logical
sence to do so. Each module should perform a single set of tasks , such as
you might place all of your printing routines in one module and all of your
sorting routines in another. Quite often I will have one module that I use
for utility functions used by procedures in multiple modules... Whatever
makes sense and helps you to keep things organized is what is best.

--
HTH...

Jim Thomlinson


"Jeff" wrote:

Hi,

I have written code and there are a number of variables that are declared at
the top of the module - so they can be used by all subs in the module.

I am expanding the code and am considering separating the new added code
into a different module because it would be organized a little better.

My question is - is there a performance difference to declaring the
variables public rather then "Module" wide. Any advice under what
circumstances to break code into different modules and when to declare public
vs module wide.

I have 1 module now, but I could break up the code into 6 modules that have
product specific data. All the variables would have to change to public
because they are common in the 6 modules.

Thanks for your help