Message 1 of 15
declare vars at module level or pass as args?

Not applicable
01-06-2002
02:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Is there a rule of thumb to decide whether to declare variables at module
scope so all proceedures in that module can use them or whether to write all
proceedures to accept args and pass the vars around that way?
Like if I have seven or so vars and several subs or funcs need to mess with
them variously are there overhead considerations like passing args uses more
memory than storing vars in module scope or???
or speed of execution? or ease of writing? or ease of understanding code?
I've read that 'global' variables as bad and in a way I guess I've thought
that module level was kind of 'global' but it seems that in vba since
there's different levels of scope available that it's not totally
unacceptable to have a variable other than inside a proceedure and,
therefore, to have to pass any values around as arguments and return values.
Or maybe I'm totally misunderstanding all this scope stuff and global
variables being a bad thing???
any suggestions?
Thanks
Mark
Is there a rule of thumb to decide whether to declare variables at module
scope so all proceedures in that module can use them or whether to write all
proceedures to accept args and pass the vars around that way?
Like if I have seven or so vars and several subs or funcs need to mess with
them variously are there overhead considerations like passing args uses more
memory than storing vars in module scope or???
or speed of execution? or ease of writing? or ease of understanding code?
I've read that 'global' variables as bad and in a way I guess I've thought
that module level was kind of 'global' but it seems that in vba since
there's different levels of scope available that it's not totally
unacceptable to have a variable other than inside a proceedure and,
therefore, to have to pass any values around as arguments and return values.
Or maybe I'm totally misunderstanding all this scope stuff and global
variables being a bad thing???
any suggestions?
Thanks
Mark