Passing value to a Forms TextBox

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

    #1

    Passing value to a Forms TextBox

    How do I pass a value from a Public Sub in a class to a forms textbox.

    I get 'Name Forms is not declared' with Forms!frmName!t xtBoxName.



    Regards


  • Scott M.

    #2
    Re: Passing value to a Forms TextBox

    Is this an ASP.NET Textbox control? If so, just use the name of the
    control, as in:

    txtUser.Text = someValue


    "Terry" <news-grps@whiteHYPHE NlightDOTme.ukw rote in message
    news:%23Wbz0ZPO HHA.4992@TK2MSF TNGP04.phx.gbl. ..
    How do I pass a value from a Public Sub in a class to a forms textbox.
    >
    I get 'Name Forms is not declared' with Forms!frmName!t xtBoxName.
    >
    >
    >
    Regards
    >
    >

    Comment

    • Stephany Young

      #3
      Re: Passing value to a Forms TextBox

      In the Public Sub in your class, you need a reference to the form concerned.
      There are many ways of achieving this but one way is:

      Dim _f As Form = My.Application. OpenForms("frmN ame")

      An object of type Form does not, of course know anything about txtBoxName,
      so you need to cast the reference to a variable of type frmName:

      Dim _f As frmName = CType(My.Applic ation.OpenForms ("frmName"), frmName)

      Now that you have the reference, you can manipulate the TextBox directly:

      _f.txtBoxName.t ext = "The quick brown fox ..."

      There are a number of nuances to this approach but if the app is a basic
      Windows Forms app then this approach should work just fine in most cases.


      "Terry" <news-grps@whiteHYPHE NlightDOTme.ukw rote in message
      news:%23Wbz0ZPO HHA.4992@TK2MSF TNGP04.phx.gbl. ..
      How do I pass a value from a Public Sub in a class to a forms textbox.
      >
      I get 'Name Forms is not declared' with Forms!frmName!t xtBoxName.
      >
      >
      >
      Regards
      >
      >

      Comment

      • Newbie Coder

        #4
        Re: Passing value to a Forms TextBox

        Here's another way of doing it:

        - Start Windows App
        - Add a button to form1
        - Add a second form
        - Add a textbox to form2

        Open form2 in code view & add this code:

        Public Shadows Sub ShowDialog(ByVa l s As String)
        TextBox1.Text = s
        MyBase.ShowDial og()
        End Sub

        Public Shadows Sub Show(ByVal s As String)
        TextBox1.Text = s
        MyBase.Show()
        End Sub

        Double-click the button in form1 & add one of these snippets:

        ' Show modal:

        Dim frm As New Form2
        frm.ShowDialog( "Hello, World!")
        frm.Dispose()

        ' Show form:

        Dim frm As New Form2
        frm.Show("Hello , World!")

        I hope this helps,

        Newbie Coder


        Comment

        • Terry

          #5
          Re: Passing value to a Forms TextBox

          Hi Again Stephany,

          Thanks again for your help. Just what I needed, I'll give it a go later
          today, it's 1 a.m. just now.

          regards

          Terry

          "Stephany Young" <noone@localhos twrote in message
          news:%23FONgvPO HHA.4848@TK2MSF TNGP04.phx.gbl. ..
          In the Public Sub in your class, you need a reference to the form
          concerned. There are many ways of achieving this but one way is:
          >
          Dim _f As Form = My.Application. OpenForms("frmN ame")
          >
          An object of type Form does not, of course know anything about txtBoxName,
          so you need to cast the reference to a variable of type frmName:
          >
          Dim _f As frmName = CType(My.Applic ation.OpenForms ("frmName"), frmName)
          >
          Now that you have the reference, you can manipulate the TextBox directly:
          >
          _f.txtBoxName.t ext = "The quick brown fox ..."
          >
          There are a number of nuances to this approach but if the app is a basic
          Windows Forms app then this approach should work just fine in most cases.
          >
          >
          "Terry" <news-grps@whiteHYPHE NlightDOTme.ukw rote in message
          news:%23Wbz0ZPO HHA.4992@TK2MSF TNGP04.phx.gbl. ..
          >How do I pass a value from a Public Sub in a class to a forms textbox.
          >>
          >I get 'Name Forms is not declared' with Forms!frmName!t xtBoxName.
          >>
          >>
          >>
          >Regards
          >>
          >>
          >
          >

          Comment

          • Terry

            #6
            Re: Passing value to a Forms TextBox

            Hi Scott,

            I'm using a Windows form, hopefully should be into ASP later this year,
            thanks.

            Regards

            "Scott M." <s-mar@nospam.nosp amwrote in message
            news:eYrcUhPOHH A.2140@TK2MSFTN GP03.phx.gbl...
            Is this an ASP.NET Textbox control? If so, just use the name of the
            control, as in:
            >
            txtUser.Text = someValue
            >
            >
            "Terry" <news-grps@whiteHYPHE NlightDOTme.ukw rote in message
            news:%23Wbz0ZPO HHA.4992@TK2MSF TNGP04.phx.gbl. ..
            >How do I pass a value from a Public Sub in a class to a forms textbox.
            >>
            >I get 'Name Forms is not declared' with Forms!frmName!t xtBoxName.
            >>
            >>
            >>
            >Regards
            >>
            >>
            >
            >

            Comment

            • Terry

              #7
              Re: Passing value to a Forms TextBox

              Hi,

              I'm guessing that form2 is discarded after the magic has worked. Usefull, I
              have seen this example on another site but it's not quite what I need just
              now. One for later in the project.

              Regards

              Terry

              "Newbie Coder" <newbie_coder@p leasespamme.com wrote in message
              news:u2jLoJQOHH A.5012@TK2MSFTN GP02.phx.gbl...
              Here's another way of doing it:
              >
              - Start Windows App
              - Add a button to form1
              - Add a second form
              - Add a textbox to form2
              >
              Open form2 in code view & add this code:
              >
              Public Shadows Sub ShowDialog(ByVa l s As String)
              TextBox1.Text = s
              MyBase.ShowDial og()
              End Sub
              >
              Public Shadows Sub Show(ByVal s As String)
              TextBox1.Text = s
              MyBase.Show()
              End Sub
              >
              Double-click the button in form1 & add one of these snippets:
              >
              ' Show modal:
              >
              Dim frm As New Form2
              frm.ShowDialog( "Hello, World!")
              frm.Dispose()
              >
              ' Show form:
              >
              Dim frm As New Form2
              frm.Show("Hello , World!")
              >
              I hope this helps,
              >
              Newbie Coder
              >
              >

              Comment

              • Newbie Coder

                #8
                Re: Passing value to a Forms TextBox

                At least I could help you in the future, Terry

                I guess you are on UK time like I am :)

                Take it easy,

                Newbie Coder
                (It's just a name)


                Comment

                • Cor Ligthert [MVP]

                  #9
                  Re: Passing value to a Forms TextBox

                  Terry,

                  The one is given by Newbie is the one if you pass from a owner to a slave,
                  the one given by Stephany is the one if you pass from a slave to an owner.
                  You did in my opinion not tell that direction.

                  In the latter case (from a child to a parent) I prefer however

                  Dim frmSlave as Form2
                  frmSlave.owner = me
                  frmSlave.Show

                  and in the slave
                  DirectCast(owne r.TextboxA) = "whatever"

                  Cor

                  "Terry" <news-grps@whiteHYPHE NlightDOTme.uks chreef in bericht
                  news:%23Wbz0ZPO HHA.4992@TK2MSF TNGP04.phx.gbl. ..
                  How do I pass a value from a Public Sub in a class to a forms textbox.
                  >
                  I get 'Name Forms is not declared' with Forms!frmName!t xtBoxName.
                  >
                  >
                  >
                  Regards
                  >
                  >

                  Comment

                  • Terry

                    #10
                    Re: Passing value to a Forms TextBox

                    Hi Cor,

                    Thanks for distinguishing between the two, I've no doubt that I will need
                    both shortly.

                    Regards
                    Terry

                    "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
                    news:eGyUgzSOHH A.1248@TK2MSFTN GP02.phx.gbl...
                    Terry,
                    >
                    The one is given by Newbie is the one if you pass from a owner to a slave,
                    the one given by Stephany is the one if you pass from a slave to an owner.
                    You did in my opinion not tell that direction.
                    >
                    In the latter case (from a child to a parent) I prefer however
                    >
                    Dim frmSlave as Form2
                    frmSlave.owner = me
                    frmSlave.Show
                    >
                    and in the slave
                    DirectCast(owne r.TextboxA) = "whatever"
                    >
                    Cor
                    >
                    "Terry" <news-grps@whiteHYPHE NlightDOTme.uks chreef in bericht
                    news:%23Wbz0ZPO HHA.4992@TK2MSF TNGP04.phx.gbl. ..
                    >How do I pass a value from a Public Sub in a class to a forms textbox.
                    >>
                    >I get 'Name Forms is not declared' with Forms!frmName!t xtBoxName.
                    >>
                    >>
                    >>
                    >Regards
                    >>
                    >>
                    >
                    >

                    Comment

                    • AMDRIT

                      #11
                      Re: Passing value to a Forms TextBox

                      I haven't seen that syntax since Access VBA. Are you attempting to interact
                      with a textbox in this manner: Forms!frmName!t xtBoxName?

                      If so,

                      Try using a dot instead of an exclamation point.

                      forms.item(myfo rmindex).txtMyT extbox

                      Example

                      public sub Test(someValue as string)
                      dim strValue as string

                      strValue = "Test:" & someValue

                      for each f as form in forms
                      if typeof f is frmTarget then
                      f.txtTarget.tex t = someValue
                      end if
                      next

                      end sub


                      "Terry" <news-grps@whiteHYPHE NlightDOTme.ukw rote in message
                      news:%23Wbz0ZPO HHA.4992@TK2MSF TNGP04.phx.gbl. ..
                      How do I pass a value from a Public Sub in a class to a forms textbox.
                      >
                      I get 'Name Forms is not declared' with Forms!frmName!t xtBoxName.
                      >
                      >
                      >
                      Regards
                      >
                      >

                      Comment

                      • Terry

                        #12
                        Re: Passing value to a Forms TextBox

                        Hi Amdrit,

                        Yup, good old Access VBA. I understand your example, I have used something
                        similar in VBA to test whether a form was open or not.

                        Thanks for the help.
                        Regards

                        "AMDRIT" <amdrit@hotmail .comwrote in message
                        news:OyIFfRbOHH A.4104@TK2MSFTN GP06.phx.gbl...
                        >I haven't seen that syntax since Access VBA. Are you attempting to
                        >interact with a textbox in this manner: Forms!frmName!t xtBoxName?
                        >
                        If so,
                        >
                        Try using a dot instead of an exclamation point.
                        >
                        forms.item(myfo rmindex).txtMyT extbox
                        >
                        Example
                        >
                        public sub Test(someValue as string)
                        dim strValue as string
                        >
                        strValue = "Test:" & someValue
                        >
                        for each f as form in forms
                        if typeof f is frmTarget then
                        f.txtTarget.tex t = someValue
                        end if
                        next
                        >
                        end sub
                        >
                        >
                        "Terry" <news-grps@whiteHYPHE NlightDOTme.ukw rote in message
                        news:%23Wbz0ZPO HHA.4992@TK2MSF TNGP04.phx.gbl. ..
                        >How do I pass a value from a Public Sub in a class to a forms textbox.
                        >>
                        >I get 'Name Forms is not declared' with Forms!frmName!t xtBoxName.
                        >>
                        >>
                        >>
                        >Regards
                        >>
                        >>
                        >
                        >

                        Comment

                        Working...