Variable Declaration

G

Guest

I'm modifying someone else's program and trying to speed it up. There is a
CheckSetup procedure that runs when the program loads (called by an autoexec
macro). CheckSetup is stored in a module in which she makes the following
declarations at the module level:
Public mydbase as Database
Public rs as Recordset
Public strSQL as String

However, once she declares these variable as Public, she then declares them
again in other Private Modules and Class modules. Is this necessary and if
not is it inefficient? My thought is that once these variables are declared
here that they do not have to be declared again in any module. Any thoughts
on this would be appreciated!
 
A

Allen Browne

Hi John

Many developers have tried using the public variables as as way of avoiding
the declarations in many procedures. In practice this doesn't work well, so
they end up giving up on the approach, and declaring them in each procedure
anyway. I'm guessing you are seeing a vestige of this commonly travelled
road.

Try removing the public variables.
Then compile (Debug menu).
If the code still compiles, you don't need them.
If it doesn't, you may have a few procedures where you have to declare them
locally.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top