Global Objects?

  • Thread starter Thread starter Shadowboxer
  • Start date Start date
S

Shadowboxer

What happened to global objects?

I want to make the main form accessible throughout all the classes as a
single instance, right now I have to make a cludgy pass back through the
class structure to get to a textbox.


Also, how do I setup an event listener on the global form that I can call
from a RaiseEvent in one of the classes?
thanks -J
 
Hi Shadowboxer,

Globals have disappeared. Everything needs to be in a class. :-(

Globals have reappeared. You can have a Module which implicitly creates
the class for you. :-)

Regards,
Fergus
 
Hi there, I recommend you create a Sub Main in a module:

Public Module EntryPoint

Public fMainForm As MainForm

Public Sub Main(Arguments() As String)

fMainForm = New MainForm
Application.Run(fMainForm)

End Sub

End Module

Now, whereever you are, you can access fMainForm to be the main form.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
 
Hi again Shadowboxer,

The beauty of a Module is that it needs so little work. You don't have to
worry about it being a class - it's all hidden.

Click on Add New Item...
Click on Module
Give it a name, eg Globals.vb, or modGlobals.vb, or whatever.

You'll see a pretty empty code window

- Module Module1
|
|_End Module

Change its name, eg Globals, or leave it as it is (but consistency
with the filename is useful).

Type your globals.
Const sProgrammer As String = "Shadowboxer"
Public iGlobalCounter As Integer = 1

These will be available everywhere without qualification.

Take a look at the example that Tom gave - it shows you how to deal with
your Main Form question.

Regards,
Fergus
 
Hello,

Shadowboxer said:
I want to make the main form accessible throughout all the classes as a
single instance, right now I have to make a cludgy pass back through the
class structure to get to a textbox.

Have a Google Groups Search on "singleton pattern".
Also, how do I setup an event listener on the global form that I
can call from a RaiseEvent in one of the classes?

Have a look at the documentation for 'AddHandler' and 'RemoveHandler'.

HTH,
Herfried K. Wagner
 
Back
Top