Why doesn't this work???

sjn78

Well-known member
Joined
May 4, 2003
Messages
255
Location
Australia
I have a child form that calls this

SB.Text("Sending Email")

The class for the above is

Class SB
Public Shared Sub Text(ByVal txt As String)
Dim frm As New FrmMain()

frm.SBMain.Text = txt

End Sub
End Class

SBMain is the statusbar.

Why wont the statusbar update on the main form?

Any help would be great.

Thanks
 
You are creating a new instance of the main form everytime. You have to pass in the instance of the form to that sub.
Something like:
Code:
Public Shared Sub Text(ByVal txt As String, ByVal yourform as FrmMain)

yourform.SBMain.Text = txt

End Sub
 
What mutant said, plus..

It wont display the text if you have panels on your status bar, so if thats the case youll need to update the panel directly. Also make sure the status bar is public so it can be accessed outside of the form. Controls are usually private by default.
 
The statubar doesnt have panels....im not that clever yet.

I changed the function to what you said and still no luck.

when calling the function, what form should I use ?

sb.text("Message", ??)


Thanks for helping out. I have only just moved to .NET from VB6 and have much to learn.
 
If you are calling that sub from your form class then just type
Code:
Me
in there.
If not from your form class than show us the code you call it from and where it is.
 
Ok, this is what I have

FrmMain with the statusbar on it
FrmEmail where I am trying to call the sb.text()
ClsMain where the sb.text is defined
 
Ok, so you update status bar only. So when you create new instance of your frmEmail, when you show it from frmMain, pass in the the instance of your status bar to frmEmail. You have to overload the constructor to do that. Put this in your FrmEmail:
Code:
Dim barinstance as StatusBar variable to hold the instance
Public Sub New(ByVal bar as StatusBar)
MyBase.New
InitializeComponent()
barinstance = bar assign the instance to variable
now you can access that statusbar in this class
End Sub
Now when you call you sub that changes text on panel call it like this:
Code:
sb.Text("Message", barinstance)
And Make you Text sub accept those arguments:
Code:
ByVal txt As String, ByVal yourbar As StatusBar
And now you can manipulate the StatusBar that is in the frmMain.
 
Back
Top