Home All Groups Group Topic Archive Search About

Referencing "Forms" objects from a module

Author
13 Jan 2006 6:14 PM
Paul Helmuth
All,

(here's an easy one)...

This is probably a stupid question - please bare with me as I am new to
dotNet.

How does one reference objects on a form from a module? In 6.0 you could
simply provide the form name as a prefix to the object within the form and
that would do it (kind of like providing a fully qualified path name to a
file).

What is the mechanism for such a reference from a VB.net module?

Thanks in advance for any insight

-Paul

Author
13 Jan 2006 6:29 PM
Debugger81
your can easily find answer, in the following code

------------------------------------------------------------------------

Module Module1

    Function A_Function()
        MessageBox.Show(" i m in module1")
    End Function

End Module

------------------------------------------------------------------------

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        Module1.A_Function()

    End Sub
End Class
------------------------------------------------------------------------
Author
13 Jan 2006 6:37 PM
Paul Helmuth
Almost.

The code snipit you provided shows the reverse.

You are referncing a module function from a form. I want to reference a form
object from a module. I have tried the 6.0 syntax which I described in my
original post - it's pretty much the same as the "form-to-module" reference
that you have illustrated.

How does one reference a form object from within a module?


Show quoteHide quote
"Debugger81" <soomrowas***@gmail.com> wrote in message
news:1137176976.878470.205790@g49g2000cwa.googlegroups.com...
> your can easily find answer, in the following code
>
> ------------------------------------------------------------------------
>
> Module Module1
>
>    Function A_Function()
>        MessageBox.Show(" i m in module1")
>    End Function
>
> End Module
>
> ------------------------------------------------------------------------
>
> Public Class Form1
>    Inherits System.Windows.Forms.Form
>
>    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>        Module1.A_Function()
>
>    End Sub
> End Class
> ------------------------------------------------------------------------
>
Author
13 Jan 2006 8:12 PM
Debugger81
Paul you can do it by making the instance of the form in module like
shown below:


Module Module1

    Function A_Function()

        Dim frmInstance As Form1
        frmInstance = New Form1

        frmInstance.callMeFunction81()

    End Function

End Module

* callMeFunction81() will be called which is in the form, Or you can do
what ever you want to do with it, as you got the instance of that form.


Paul Helmuth wrote:
Show quoteHide quote
> Almost.
>
> The code snipit you provided shows the reverse.
>
> You are referncing a module function from a form. I want to reference a form
> object from a module. I have tried the 6.0 syntax which I described in my
> original post - it's pretty much the same as the "form-to-module" reference
> that you have illustrated.
>
> How does one reference a form object from within a module?
>
>
> "Debugger81" <soomrowas***@gmail.com> wrote in message
> news:1137176976.878470.205790@g49g2000cwa.googlegroups.com...
> > your can easily find answer, in the following code
> >
> > ------------------------------------------------------------------------
> >
> > Module Module1
> >
> >    Function A_Function()
> >        MessageBox.Show(" i m in module1")
> >    End Function
> >
> > End Module
> >
> > ------------------------------------------------------------------------
> >
> > Public Class Form1
> >    Inherits System.Windows.Forms.Form
> >
> >    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles MyBase.Load
> >        Module1.A_Function()
> >
> >    End Sub
> > End Class
> > ------------------------------------------------------------------------
> >
Author
13 Jan 2006 6:33 PM
Armin Zingler
Show quote Hide quote
"Paul Helmuth" <phelm***@cvit.com> schrieb
> All,
>
> (here's an easy one)...
>
> This is probably a stupid question - please bare with me as I am new
> to dotNet.
>
> How does one reference objects on a form from a module? In 6.0 you
> could simply provide the form name as a prefix to the object within
> the form and that would do it (kind of like providing a fully
> qualified path name to a file).
>
> What is the mechanism for such a reference from a VB.net module?
>
> Thanks in advance for any insight


If possible, don't use a Module. See previous discussions in this group.

Why don't you put the code in the Form?


Armin
Author
13 Jan 2006 7:48 PM
Herfried K. Wagner [MVP]
"Armin Zingler" <az.nospam@freenet.de> schrieb:
> If possible, don't use a Module. See previous discussions in this group.

That's just your personal opinion.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
13 Jan 2006 8:26 PM
Armin Zingler
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb
> "Armin Zingler" <az.nospam@freenet.de> schrieb:
> > If possible, don't use a Module. See previous discussions in this
> > group.
>
> That's just your personal opinion.

Whom else's opinion should I post? It's not only an opinion but also a
suggestion.


Armin
Author
14 Jan 2006 6:52 AM
Cor Ligthert [MVP]
>> If possible, don't use a Module. See previous discussions in this group.
>
> That's just your personal opinion.
>
Absolutely not, in my opinion exact the right answer from Armin

Cor
Author
14 Jan 2006 10:50 AM
Armin Zingler
"Armin Zingler" <az.nospam@freenet.de> schrieb
> If possible, don't use a Module. See previous discussions in this
> group.

To clarify this...  :-)

It could be understood as: "Don't use a Module. That's the
conlusions of previous discussions.".

What I meant was:
"Don't use a Module. The usage of modules has already been discussed, so
look up the previous threads."

Thus, the last sentence was not to support my own opinion and give a (maybe
wrong) impression of what's the conclusion of previous threads, but it was
only to give a general hint to discussions about this subject (that also
mention advantages of modules).

(IMO, everything in a module is part of "*the* application". "*The*
application" is an object (singleton in this case) => "Class App" with
shared methods (my personal way of thinking only))


Armin
Author
14 Jan 2006 12:44 PM
m.posseth
Huh ???

Well i guess it is your opinion , and it seems also to be Cor`s opinion   so
Herrfried was right when he said that is just your opinion  :-)

probably he said this,  because if you read the comment someone might think
that it is bad coding practice to use a module at all

regards

Michel Posseth [MCP]




Show quoteHide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:%23SBVLiPGGHA.3864@tk2msftngp13.phx.gbl...
> "Armin Zingler" <az.nospam@freenet.de> schrieb
>> If possible, don't use a Module. See previous discussions in this
>> group.
>
> To clarify this...  :-)
>
> It could be understood as: "Don't use a Module. That's the
> conlusions of previous discussions.".
>
> What I meant was:
> "Don't use a Module. The usage of modules has already been discussed, so
> look up the previous threads."
>
> Thus, the last sentence was not to support my own opinion and give a
> (maybe
> wrong) impression of what's the conclusion of previous threads, but it was
> only to give a general hint to discussions about this subject (that also
> mention advantages of modules).
>
> (IMO, everything in a module is part of "*the* application". "*The*
> application" is an object (singleton in this case) => "Class App" with
> shared methods (my personal way of thinking only))
>
>
> Armin
>
Author
14 Jan 2006 6:58 PM
Cor Ligthert [MVP]
>Well i guess it is your opinion , and it seems also to be Cor`s opinion
>so Herrfried was right when he said that is just your opinion  :-)


Ik zal het voor jouw in het nederlands doen.

Als het Armin en mijn opinion is, dan is het niet *alleen maar* de
persoonlijke opinie van Armin, maar een opinie van meer personen.

Translated.

I'll do it for you in Dutch.

If it is the opinion of Armin and mine opinion, than it is not *just* the
personal opinion from Amrin, however an opinion from more persons.

For the rest is real developping a going on traject where what was yesterday
right is tomorrow wrong.

The pleasure of Visual Basic Net is that it is not so commanding as other
languages. Because I have read many messages from you, is my believe that we
share that opinion.

Cor
Author
14 Jan 2006 10:37 PM
Armin Zingler
"m.posseth" <mich***@nohausystems.nl> schrieb
> Huh ???
>
> Well i guess it is your opinion , and it seems also to be Cor`s
> opinion   so Herrfried was right when he said that is just your
> opinion  :-)
>
> probably he said this,  because if you read the comment someone might
> think that it is bad coding practice to use a module at all

But that's what I wrote in my previous post!?? I saw that it could have been
misunderstood - as Herfried probably did - thus the clarification.


Armin
Author
15 Jan 2006 10:32 AM
m.posseth
Armin , Cor

i just wanted to make clear that a opinion is not a fact  , even if it is
shared by multiple persons

from my personal point of view this was not clear in the thread , it looked
to me as if it is bad coding practice to use a module

> But that's what I wrote in my previous post!??

I missed  the previous post that was indeed  exactly the facto that i missed
before .
It arived on my computer after i wrote the response   i read the newsgroup
through nova.planet.nl   and through news.microsoft.com  on different
computers , the planet server seems to be  late with its delivery sometimes
..

I am with you if you say that , you should try to avoid the usage of modules
( although this is also a personal opinion ;-)

regards

Michel Posseth [MCP]




Show quoteHide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:O%23wtKtVGGHA.1032@TK2MSFTNGP15.phx.gbl...
> "m.posseth" <mich***@nohausystems.nl> schrieb
>> Huh ???
>>
>> Well i guess it is your opinion , and it seems also to be Cor`s
>> opinion   so Herrfried was right when he said that is just your
>> opinion  :-)
>>
>> probably he said this,  because if you read the comment someone might
>> think that it is bad coding practice to use a module at all
>
> But that's what I wrote in my previous post!?? I saw that it could have
> been misunderstood - as Herfried probably did - thus the clarification.
>
>
> Armin
>
Author
15 Jan 2006 10:52 AM
Armin Zingler
Show quote Hide quote
"m.posseth" <mich***@nohausystems.nl> schrieb
> Armin , Cor
>
> i just wanted to make clear that a opinion is not a fact  , even if
> it is shared by multiple persons
>
> from my personal point of view this was not clear in the thread , it
> looked to me as if it is bad coding practice to use a module
>
> > But that's what I wrote in my previous post!??
>
> I missed  the previous post that was indeed  exactly the facto that
> i missed before .
> It arived on my computer after i wrote the response   i read the
> newsgroup through nova.planet.nl   and through news.microsoft.com
> on different computers , the planet server seems to be  late with
> its delivery sometimes .

Ok, I see. :-)

> I am with you if you say that , you should try to avoid the usage of
> modules ( although this is also a personal opinion ;-)


But isn't this your personal opinion only? ;-))) Don't answer, I do
understand. :)


Armin
Author
15 Jan 2006 12:12 PM
Cor Ligthert [MVP]
Michel,

You probably have seen that I can as well use the nova newsserver.

However, I use direct the microsoft newsserver, it is quicker and has in my
opinion exactly the right  retention time.

news://news.microsoft.com/microsoft.public.dotnet.languages.vb

Why don't you try it yourself.

I can not remember me that I forever wrote something as a fact here in these
newsgroups. I have to often seen that what is a fact today was rubish
tomorrow. Maybe is that the reason that I react forever on people who write
things from which they tell it are facts.

Even 1+1 is not always 2 when option strict is off.

Cor
Author
13 Jan 2006 8:15 PM
Kerry Moorman
Paul,

You could pass a reference to the form to the code in the module.

Kerry Moorman


Show quoteHide quote
"Paul Helmuth" wrote:

> All,
>
> (here's an easy one)...
>
> This is probably a stupid question - please bare with me as I am new to
> dotNet.
>
> How does one reference objects on a form from a module? In 6.0 you could
> simply provide the form name as a prefix to the object within the form and
> that would do it (kind of like providing a fully qualified path name to a
> file).
>
> What is the mechanism for such a reference from a VB.net module?
>
> Thanks in advance for any insight
>
> -Paul
>
>
>
Author
13 Jan 2006 9:19 PM
Jay Taplin
When you say "objects ON a form", do you mean controls?  If not, please
ignore this post. If so, though...

I would do this as a property of the form, exposing the object.  This gives
your form control over itself, provides true encapsulation, and allows you
the ability to reject requests for the object, etc., etc.  Directly
referencing the control is, IMHO, not the best programming practice for
these reasons.

In the form:

    Public ReadOnly Property NameTextBox() As TextBox
        Get
            NameTextBox = TextBox1
        End Get
    End Property


In the module:

    Dim mForm1 As Form1

    Sub Test()
        MsgBox(mForm1.NameTextBox.Text())
    End Sub

Where NameTextBox is a descriptive name of your text box object, and mForm1
is an object that references your form.

One last thing... I have no idea what your application is, and I don't mean
to preach at all, but you may want to take the encapsulation concept one
step further and expose only values from your control, such as a property
that exposes the text value of a text box.
Author
13 Jan 2006 9:20 PM
Jay Taplin
When you say "objects ON a form", do you mean controls?  If not, please
ignore this post. If so, though...

I would do this as a property of the form, exposing the object.  This gives
your form control over itself, provides true encapsulation, and allows you
the ability to reject requests for the object, etc., etc.  Directly
referencing the control is, IMHO, not the best programming practice for
these reasons.

In the form:

    Public ReadOnly Property NameTextBox() As TextBox
        Get
            NameTextBox = TextBox1
        End Get
    End Property


In the module:

    Dim mForm1 As Form1

    Sub Test()
        MsgBox(mForm1.NameTextBox.Text())
    End Sub

Where NameTextBox is a descriptive name of your text box object, and mForm1
is an object that references your form.

One last thing... I have no idea what your application is, and I don't mean
to preach at all, but you may want to take the encapsulation concept one
step further and expose only values from your control, such as a property
that exposes the text value of a text box.


Show quoteHide quote
"Paul Helmuth" <phelm***@cvit.com> wrote in message
news:T5Sxf.8564$dW3.627@newssvr21.news.prodigy.com...
> All,
>
> (here's an easy one)...
>
> This is probably a stupid question - please bare with me as I am new to
> dotNet.
>
> How does one reference objects on a form from a module? In 6.0 you could
> simply provide the form name as a prefix to the object within the form and
> that would do it (kind of like providing a fully qualified path name to a
> file).
>
> What is the mechanism for such a reference from a VB.net module?
>
> Thanks in advance for any insight
>
> -Paul
>