PC Review


Reply
Thread Tools Rate Thread

Accessing an instance of a form from another class

 
 
Duane Roelands
Guest
Posts: n/a
 
      2nd Dec 2003
Hello all.

I'm having some difficulty accessing the .text property of a label on my
startup form.

My form is frmStartup, and this is the application's startup object (as
opposed to sub Main() ).

I have a module called "xmlHandler", and in that module, I would like to
change the .text property of the lblStatusMessage label which is on
frmStartup.

Now, if my startup object were sub Main(), this would be simple...

dim myForm as new frmStartup
myForm.lblStatusMessage.text = "foo"

However, because my startup object is frmStartup, I'm not sure what the
reference to the instance of the frmStartup class is. Any guidance would be
appreciated. Thank you in advance.

Duane Roelands


 
Reply With Quote
 
 
 
 
Paul [Paradise Solutions]
Guest
Posts: n/a
 
      2nd Dec 2003
Well, as I understand it, you can't do that because to reference the
form from the module you'd have to instantiate a new reference - which
wouldn't help you much because your visible form would be a different
instance to the one you were setting the value of.
It would probably be better to make the xml module into a class, and let
the form consume it via properties and such.


Paul

Duane Roelands wrote:

> Hello all.
>
> I'm having some difficulty accessing the .text property of a label on my
> startup form.
>
> My form is frmStartup, and this is the application's startup object (as
> opposed to sub Main() ).
>
> I have a module called "xmlHandler", and in that module, I would like to
> change the .text property of the lblStatusMessage label which is on
> frmStartup.
>
> Now, if my startup object were sub Main(), this would be simple...
>
> dim myForm as new frmStartup
> myForm.lblStatusMessage.text = "foo"
>
> However, because my startup object is frmStartup, I'm not sure what the
> reference to the instance of the frmStartup class is. Any guidance would be
> appreciated. Thank you in advance.
>
> Duane Roelands
>
>


 
Reply With Quote
 
Yves Zouzouambe
Guest
Posts: n/a
 
      3rd Dec 2003
The easiest thing would definately be to have a Sub Main() to do this
work for you. If this is not possible for some reason then I would
have the Load event on the form call a function on your module to send
a reference to itself, then have that function change the label's text
property.

"Duane Roelands" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Hello all.
>
> I'm having some difficulty accessing the .text property of a label on my
> startup form.
>
> My form is frmStartup, and this is the application's startup object (as
> opposed to sub Main() ).
>
> I have a module called "xmlHandler", and in that module, I would like to
> change the .text property of the lblStatusMessage label which is on
> frmStartup.
>
> Now, if my startup object were sub Main(), this would be simple...
>
> dim myForm as new frmStartup
> myForm.lblStatusMessage.text = "foo"
>
> However, because my startup object is frmStartup, I'm not sure what the
> reference to the instance of the frmStartup class is. Any guidance would be
> appreciated. Thank you in advance.
>
> Duane Roelands

 
Reply With Quote
 
fd123456
Guest
Posts: n/a
 
      3rd Dec 2003
Hi Duane,

You should pass the reference of the label to the xmlHandler method :

In frmStartup:

xmlHandler.SomeFunction(myLabel)

in xmlHandler :

Public Sub SomeFunction(ByRef L as Label)
....do some calculations...
L.Text = result.ToString
End Sub

If you're not calling the function from frmStartup, you can still pass
the Label ByRef along a chain.

HTH,

Michel



"Duane Roelands" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Hello all.
>
> I'm having some difficulty accessing the .text property of a label on my
> startup form.
>
> My form is frmStartup, and this is the application's startup object (as
> opposed to sub Main() ).
>
> I have a module called "xmlHandler", and in that module, I would like to
> change the .text property of the lblStatusMessage label which is on
> frmStartup.
>
> Now, if my startup object were sub Main(), this would be simple...
>
> dim myForm as new frmStartup
> myForm.lblStatusMessage.text = "foo"
>
> However, because my startup object is frmStartup, I'm not sure what the
> reference to the instance of the frmStartup class is. Any guidance would be
> appreciated. Thank you in advance.
>
> Duane Roelands

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WMI error accessing class instance at start with SP2 XP Home or Pr =?Utf-8?B?RHVzdHk=?= Windows XP Help 1 8th May 2007 10:19 PM
accessing a class instance from a separate class running in a separate thread titan nyquist Microsoft C# .NET 12 10th Apr 2007 12:27 PM
Accessing Owner class instance possible? Cyril Gupta Microsoft VB .NET 5 5th Jan 2006 12:32 AM
How can I create an instance of a class (form) with only it's name Rene Mansveld Microsoft Dot NET Framework Forms 6 18th Nov 2004 05:44 PM
Accessing Instance Class and Variables accross entire application Juan Gabriel Del Cid Microsoft C# .NET 2 20th Oct 2003 08:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:59 PM.