global variables

J

John A Grandy

In a WinForms app, how to implement the analog of global variables in a VB6
app ?
 
P

Peter Thornqvist

In a WinForms app, how to implement the analog of global variables in a
VB6 app ?

You should really, really avoid global variables, they are bad(TM).

If you have no other option, create a class with static properties/fields
for each variable you need. For good measure, declare a private constructor
so the class cannot be instantiated.
 
E

Emby

Everything John said is sensible - although IMHO there are definitely times
when global variables make sense.

But, as evil as it may be, one can still implement a VB Module, which is
roughly the equivalent of a VB6 "General" or BAS module.

It appears that the way .NET treats these is essentially what John
recommends to do - it creates a static (or Shared in VB) entity - which
looks an awful lot like a class - where all routines are automatically also
shared.

Anyone know exactly what a VB Module is ?

Anyway, that is one way to implement global members.

Cheers,
 
E

Emby

Sorry - got the names swapped - John asked the original question - it was
Peter that offered a response! Duh!

So, Everything PETER said is sensible ... etc ...
 
P

Peter Thornqvist

But, as evil as it may be, one can still implement a VB Module, which is
roughly the equivalent of a VB6 "General" or BAS module.

Since I don't know very little about VB your suggestion might be a lot
better than mine.
 

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