Referencing "Forms" objects from a module

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Helmuth

    #1

    Referencing "Forms" objects from a module

    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


  • Debugger81

    #2
    Re: Referencing "Forms&quo t; objects from a module

    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(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    Module1.A_Funct ion()

    End Sub
    End Class
    ------------------------------------------------------------------------

    Comment

    • Paul Helmuth

      #3
      Re: Referencing "Forms&quo t; objects from a module

      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 " <soomrowaseem@g mail.com> wrote in message
      news:1137176976 .878470.205790@ g49g2000cwa.goo glegroups.com.. .[color=blue]
      > 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(ByVa l sender As System.Object, ByVal e As
      > System.EventArg s) Handles MyBase.Load
      > Module1.A_Funct ion()
      >
      > End Sub
      > End Class
      > ------------------------------------------------------------------------
      >[/color]


      Comment

      • Armin Zingler

        #4
        Re: Referencing &quot;Forms&quo t; objects from a module

        "Paul Helmuth" <phelmuth@cvit. com> schrieb[color=blue]
        > 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[/color]


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

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


        Armin

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Referencing &quot;Forms&quo t; objects from a module

          "Armin Zingler" <az.nospam@free net.de> schrieb:[color=blue]
          > If possible, don't use a Module. See previous discussions in this group.[/color]

          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/>

          Comment

          • Debugger81

            #6
            Re: Referencing &quot;Forms&quo t; objects from a module

            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.cal lMeFunction81()

            End Function

            End Module

            * callMeFunction8 1() 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:[color=blue]
            > 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 " <soomrowaseem@g mail.com> wrote in message
            > news:1137176976 .878470.205790@ g49g2000cwa.goo glegroups.com.. .[color=green]
            > > 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(ByVa l sender As System.Object, ByVal e As
            > > System.EventArg s) Handles MyBase.Load
            > > Module1.A_Funct ion()
            > >
            > > End Sub
            > > End Class
            > > ------------------------------------------------------------------------
            > >[/color][/color]

            Comment

            • Kerry Moorman

              #7
              RE: Referencing &quot;Forms&quo t; objects from a module

              Paul,

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

              Kerry Moorman


              "Paul Helmuth" wrote:
              [color=blue]
              > 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
              >
              >
              >[/color]

              Comment

              • Armin Zingler

                #8
                Re: Referencing &quot;Forms&quo t; objects from a module

                "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb[color=blue]
                > "Armin Zingler" <az.nospam@free net.de> schrieb:[color=green]
                > > If possible, don't use a Module. See previous discussions in this
                > > group.[/color]
                >
                > That's just your personal opinion.[/color]

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


                Armin

                Comment

                • Jay Taplin

                  #9
                  Re: Referencing &quot;Forms&quo t; objects from a module

                  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.N ameTextBox.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.


                  Comment

                  • Jay Taplin

                    #10
                    Re: Referencing &quot;Forms&quo t; objects from a module

                    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.N ameTextBox.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.


                    "Paul Helmuth" <phelmuth@cvit. com> wrote in message
                    news:T5Sxf.8564 $dW3.627@newssv r21.news.prodig y.com...[color=blue]
                    > 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
                    >[/color]


                    Comment

                    • Cor Ligthert [MVP]

                      #11
                      Re: Referencing &quot;Forms&quo t; objects from a module

                      >> If possible, don't use a Module. See previous discussions in this group.[color=blue]
                      >
                      > That's just your personal opinion.
                      >[/color]
                      Absolutely not, in my opinion exact the right answer from Armin

                      Cor


                      Comment

                      • Armin Zingler

                        #12
                        Re: Referencing &quot;Forms&quo t; objects from a module

                        "Armin Zingler" <az.nospam@free net.de> schrieb[color=blue]
                        > If possible, don't use a Module. See previous discussions in this
                        > group.[/color]

                        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

                        Comment

                        • m.posseth

                          #13
                          Re: Referencing &quot;Forms&quo t; objects from a module

                          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]




                          "Armin Zingler" <az.nospam@free net.de> wrote in message
                          news:%23SBVLiPG GHA.3864@tk2msf tngp13.phx.gbl. ..[color=blue]
                          > "Armin Zingler" <az.nospam@free net.de> schrieb[color=green]
                          >> If possible, don't use a Module. See previous discussions in this
                          >> group.[/color]
                          >
                          > 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
                          >[/color]


                          Comment

                          • Cor Ligthert [MVP]

                            #14
                            Re: Referencing &quot;Forms&quo t; objects from a module

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


                            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


                            Comment

                            • Armin Zingler

                              #15
                              Re: Referencing &quot;Forms&quo t; objects from a module

                              "m.posseth" <michelp@nohaus ystems.nl> schrieb[color=blue]
                              > 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[/color]

                              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

                              Comment

                              Working...