By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,290 Members | 1,263 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,290 IT Pros & Developers. It's quick & easy.

In my module I'm able to read/write to form objects, but I can't modify StatusBar.Text, why?

P: n/a
Hi Gang,
I've had this happen with a couple of controls now, but my patience has worn
thin. Can somebody tell me why I can read/write to most objects on my form
from my module, but not when working with StatusBar.Text?
Thanks in Advance,
Christian Blackburn

My Code:
Public Class frmMain

Friend WithEvents StatusBar As System.Windows.Forms.StatusBar

'StatusBar

'

Me.StatusBar.Location = New System.Drawing.Point(0, 291)

Me.StatusBar.Name = "StatusBar"

Me.StatusBar.Size = New System.Drawing.Size(240, 22)

Me.StatusBar.TabIndex = 25

Me.StatusBar = New System.Windows.Forms.StatusBar

'frmMain

'

Me.Controls.Add(Me.StatusBar)

Private Sub mnuWriteToStatusBar_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles mnuWriteToStatusBar.Click

StatusBar.Text = "I'm from the form's code"

End Sub

Private Sub mnuAddToStatusBarFromModule_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles mnuAddToStatusBarFromModule.Click

WriteToStatusBar()

End Sub

End Class

Module App

'Creates an object reference to our application's form, because otherwise we
can't work with it (lame-o)

Public objfrmMain As New frmMain

Public Sub WriteToStatusBar()

objfrmMain.StatusBar.Text = "I'm from the module."

End Sub

End Module


Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb
Hi Gang,
I've had this happen with a couple of controls now, but my patience
has worn thin. Can somebody tell me why I can read/write to most
objects on my form from my module, but not when working with
StatusBar.Text? Thanks in Advance,
Christian Blackburn

My Code:
Public Class frmMain

Friend WithEvents StatusBar As System.Windows.Forms.StatusBar

'StatusBar

'

Me.StatusBar.Location = New System.Drawing.Point(0, 291)

Me.StatusBar.Name = "StatusBar"

Me.StatusBar.Size = New System.Drawing.Size(240, 22)

Me.StatusBar.TabIndex = 25

Me.StatusBar = New System.Windows.Forms.StatusBar

'frmMain

'

Me.Controls.Add(Me.StatusBar)

Private Sub mnuWriteToStatusBar_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles mnuWriteToStatusBar.Click

StatusBar.Text = "I'm from the form's code"

End Sub

Private Sub mnuAddToStatusBarFromModule_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
mnuAddToStatusBarFromModule.Click

WriteToStatusBar()

End Sub

End Class

Module App

'Creates an object reference to our application's form, because
otherwise we can't work with it (lame-o)

Public objfrmMain As New frmMain

Public Sub WriteToStatusBar()

objfrmMain.StatusBar.Text = "I'm from the module."

End Sub

End Module

Is the variable declared in the module (objfrmMain) holding the reference to
the form the same object that you are showing? Means: Do you call
objfrmMain.Show
anywhere? If not, you are creating two instances of the form and changing
the statusbar text of the invisible form.
--
Armin

Nov 20 '05 #2

P: n/a
> Is the variable declared in the module (objfrmMain) holding the reference
to
the form the same object that you are showing? Means: Do you call
objfrmMain.Show
anywhere? If not, you are creating two instances of the form and changing
the statusbar text of the invisible form.
--
Armin


Hi Armin,
You would have to be absolutely correct. It seems perfectly logical that I
would be modifying the invisible copy. That's really funny though I tried
to tell my VB teacher that what he was doing didn't make much sense.
However he said it was correct and so I just did what he said and most of
the time that works :). So how should I go about accessing my form's
properties/methods from a module when the form is my Sub_Main? He's a Fox
Pro programmer mainly and really doesn't seem to know VB that well. I can
tell, because I've been programming in VB5-6 (and a little bit of VB1 for
Dos) for 5 years now.
Thanks a Zillion,
Christian Blackburn

Nov 20 '05 #3

P: n/a
Hi Armin,
I take that back read/writing the properties didn't work at all. The reason
I thought it was working is because I created a collection of picture boxes
in my module that was a collection of the form's picture boxes. Obviously
read/writing to the collection worked fine, because I was working with the
correct set of picture boxes.
You Da Man,
Christian

"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> wrote in message
news:Of*************@TK2MSFTNGP12.phx.gbl...
Is the variable declared in the module (objfrmMain) holding the reference
to
the form the same object that you are showing? Means: Do you call
objfrmMain.Show
anywhere? If not, you are creating two instances of the form and
changing the statusbar text of the invisible form.
--
Armin


Hi Armin,
You would have to be absolutely correct. It seems perfectly logical that

I would be modifying the invisible copy. That's really funny though I tried
to tell my VB teacher that what he was doing didn't make much sense.
However he said it was correct and so I just did what he said and most of
the time that works :). So how should I go about accessing my form's
properties/methods from a module when the form is my Sub_Main? He's a Fox
Pro programmer mainly and really doesn't seem to know VB that well. I can
tell, because I've been programming in VB5-6 (and a little bit of VB1 for
Dos) for 5 years now.
Thanks a Zillion,
Christian Blackburn

Nov 20 '05 #4

P: n/a
"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb
Hi Armin,
I take that back read/writing the properties didn't work at all. The
reason I thought it was working is because I created a collection of
picture boxes in my module that was a collection of the form's
picture boxes. Obviously read/writing to the collection worked fine,
because I was working with the correct set of picture boxes.
You Da Man,
Christian


Ummm... Problem solved now?

If not: ;-)
Why don't you put the code in the form?
--
Armin
Nov 20 '05 #5

P: n/a
Hi Armin,

"Armin Zingler" <az*******@freenet.de> wrote in message
news:uk**************@TK2MSFTNGP12.phx.gbl...
"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb
Hi Armin,
I take that back read/writing the properties didn't work at all. The
reason I thought it was working is because I created a collection of
picture boxes in my module that was a collection of the form's
picture boxes. Obviously read/writing to the collection worked fine,
because I was working with the correct set of picture boxes.
You Da Man,
Christian Ummm... Problem solved now?


Not exactly I would still like to be able to work with my form from a module
that seems like normal VB functionality to me. I like to keep all my events
in the Form and procedures and functions in one or more modules. It's just
neater that way since I tend to write a plethora of procedures and functions
:).

If not: ;-)
Why don't you put the code in the form?
I agree that this is an easy work around, but surely there must be a way to
reference the one and only form in my project from my one and only module
(currently anyways)?

Thanks Again,
Christian Blackburn

--
Armin

Nov 20 '05 #6

P: n/a
"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb
Hi Armin,

"Armin Zingler" <az*******@freenet.de> wrote in message
news:uk**************@TK2MSFTNGP12.phx.gbl...
"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb
Hi Armin,
I take that back read/writing the properties didn't work at all.
The reason I thought it was working is because I created a
collection of picture boxes in my module that was a collection of
the form's picture boxes. Obviously read/writing to the
collection worked fine, because I was working with the correct
set of picture boxes. You Da Man,
Christian

Ummm... Problem solved now?


Not exactly I would still like to be able to work with my form from a
module that seems like normal VB functionality to me. I like to keep
all my events in the Form and procedures and functions in one or more
modules. It's just neater that way since I tend to write a plethora
of procedures and functions :).


If you are collecting functions related to a Form in a Module, it's much
more neater when you put it into the From. :)
If not: ;-)
Why don't you put the code in the form?


I agree that this is an easy work around, but surely there must be a
way to reference the one and only form in my project from my one and
only module (currently anyways)?


Pass the form to the module, or show the Form declared and created in the
module _instead_ of the form instance that you are showing currently.
--
Armin

Nov 20 '05 #7

P: n/a
Hi Armin,
If you are collecting functions related to a Form in a Module, it's much
more neater when you put it into the From. :)
Well now we are getting into matters of personal preference :). I just
don't like to have all those functions and procedures in one place I'm sure
some people, if not most, do. I'll be the first to agree that it requires a
bit more syntax to make it happen, but I suppose not if you use "Imports"
which I'll have to look into.
If not: ;-)
Why don't you put the code in the form?


I agree that this is an easy work around, but surely there must be a
way to reference the one and only form in my project from my one and
only module (currently anyways)?


Pass the form to the module, or show the Form declared and created in the
module _instead_ of the form instance that you are showing currently.


Okay so here's what wound up working:

Form_Load Code:
'Tells the module what FOrm objfrmMain represents

objfrmMain = Me
Module Declaration:

'Creates an object reference to our application's form, because otherwise we
can't work with it (lame-o)

Public objfrmMain As frmMain

Armin


Thanks for helping me get that working,
Christian Blackburn
Nov 20 '05 #8

P: n/a
Hi Armin,
Since it is correct that working with forms from forms requires less syntax.
I guess I will have to get used to doing that. I'll try it out on this
project for kicks and giggles. Who knows maybe I'll like it.
Cheers,
Christian Blackburn
"Armin Zingler" <az*******@freenet.de> wrote in message
news:uE*************@tk2msftngp13.phx.gbl...
"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb
Hi Armin,

"Armin Zingler" <az*******@freenet.de> wrote in message
news:uk**************@TK2MSFTNGP12.phx.gbl...
"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb
> Hi Armin,
> I take that back read/writing the properties didn't work at all.
> The reason I thought it was working is because I created a
> collection of picture boxes in my module that was a collection of
> the form's picture boxes. Obviously read/writing to the
> collection worked fine, because I was working with the correct
> set of picture boxes. You Da Man,
> Christian
Ummm... Problem solved now?


Not exactly I would still like to be able to work with my form from a
module that seems like normal VB functionality to me. I like to keep
all my events in the Form and procedures and functions in one or more
modules. It's just neater that way since I tend to write a plethora
of procedures and functions :).


If you are collecting functions related to a Form in a Module, it's much
more neater when you put it into the From. :)
If not: ;-)
Why don't you put the code in the form?


I agree that this is an easy work around, but surely there must be a
way to reference the one and only form in my project from my one and
only module (currently anyways)?


Pass the form to the module, or show the Form declared and created in the
module _instead_ of the form instance that you are showing currently.
--
Armin

Nov 20 '05 #9

P: n/a
"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb
Hi Armin,
Since it is correct that working with forms from forms requires less
syntax. I guess I will have to get used to doing that. I'll try it
out on this project for kicks and giggles. Who knows maybe I'll like
it. Cheers,
Christian Blackburn


Let us know. :-)
--
Armin

Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.