Re: VB6 and global variables
From: Gary German (garyg_at_NOSPAMXshastasoftware.com)
Date: 04/12/04
- Next message: YYZ: "Re: VB6 and global variables"
- Previous message: Bonj: "Re: performance of subs vs. functions"
- In reply to: Pete: "VB6 and global variables"
- Next in thread: J French: "Re: VB6 and global variables"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 12 Apr 2004 13:18:40 -0700
"Pete" <anonymous@discussions.microsoft.com> wrote in message
news:60F7051F-537A-4DE8-B4CE-C14309B42B3B@microsoft.com...
> Hi All,
>
> Let me start by saying I know it is a bad programming practice.....
>
> If you have a GLOBAL variable (in a bas module) and you have a form and
inside of that form you have a variable that uses the same name as the
GLOBAL, how do you access the GLOBAL and not the routines version of the
variable?
>
>
> ** This is in VB6 sp3.
>
> Thanks for your help
It's a little-known fact that you can use the module name, and dot syntax
together. So, if you have a module named "Globals", and a public variable
in the module named "Foo", you can refer to it in your code as Globals.Foo.
That said, this is not usually a good idea. Most shops use coding standards
that emphasize scope as part of the name. I use an "m" prefix to designate
module-level scope, and a "g" prefix to indicate global-level scope. So,
using the example above, my global scoped module would be named something
like "gsFoo" (to indicate a global string variable", or "msFoo" to indicate
a module level string variable.
BTW - why are you using SP3? SP5 has been out for a long time now, and SP6
was recently released (but, many are urging caution before applying SP6).
GG
http://www.shastasoftware.com - Shasta Software - Consulting, Design, and
Programming Services
http://www.CycliStats.com - CycliStats - Software for Cyclists
http://www.StrideWare.com - StrideWare - Software for Runners and Walkers
- Next message: YYZ: "Re: VB6 and global variables"
- Previous message: Bonj: "Re: performance of subs vs. functions"
- In reply to: Pete: "VB6 and global variables"
- Next in thread: J French: "Re: VB6 and global variables"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|