Referencing controls on an EXISTING instance of form

  • Thread starter Thread starter Paul Bromley
  • Start date Start date
P

Paul Bromley

Please help with this one - I have scoured the newsgroups for information on
this, and all of the responses relate to how to refernce controls on a NEW
instanc of a form and not an exitsing one. I wish to access controls on an
EXISTING instance of my form from a module.

I have found one suggestion mentioned twice that works well - is this a
corect way of achieving this aim, or is there a neater alternative:-

The answer that I have found is to create a module with a Sub Main in it and
set this as the Startup Object:-

Module Startup
Public myMainForm As Form1
Sub Main()
myMainForm = New Form1
Windows.forms.Application.Run(myMainform)
End Sub
End Module

As I say - this works well, but is there a better way of doing this??

Many thanks


Paul Bromley
 
Paul Bromley said:
Please help with this one - I have scoured the newsgroups for
information on this, and all of the responses relate to how to
refernce controls on a NEW instanc of a form and not an exitsing one.
I wish to access controls on an EXISTING instance of my form from a
module.

I have found one suggestion mentioned twice that works well - is this
a corect way of achieving this aim, or is there a neater
alternative:-

The answer that I have found is to create a module with a Sub Main in
it and set this as the Startup Object:-

Module Startup
Public myMainForm As Form1
Sub Main()
myMainForm = New Form1
Windows.forms.Application.Run(myMainform)
End Sub
End Module

As I say - this works well, but is there a better way of doing
this??

Yes. If you want to access an object, pass the reference to the object that
needs the reference. This is the case for all other types of objects, so I
don't see the difference to Forms.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Back
Top