Unable to reference form field...

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

    Unable to reference form field...

    I have the following code that references a "textbox" on a form. I want to
    pass the value of this textbox to a stored procedure as a parameter. This
    code is located on a different form obviously. I thought that I would be
    able to reference the textbox simply by placing the name of the form it is
    located on (class name) in front as follows...

    param1 = frmSteelPlates. txtJobNo.Text

    I am getting the following error when I debug the line to see what the value
    of the text box actually is...

    "Reference to a non-shared member requires an object reference"

    What am I missing here?

    Thanks, Brad


  • kimiraikkonen

    #2
    Re: Unable to reference form field...

    On Jun 3, 6:52 pm, "Brad Pears" <br...@truenort hloghomes.comwr ote:
    I have the following code that references a "textbox" on a form. I want to
    pass the value of this textbox to a stored procedure as a parameter. This
    code is located on a different form obviously. I thought that I would be
    able to reference the textbox simply by placing the name of the form it is
    located on (class name) in front as follows...
    >
    param1 = frmSteelPlates. txtJobNo.Text
    >
    I am getting the following error when I debug the line to see what the value
    of the text box actually is...
    >
    "Reference to a non-shared member requires an object reference"
    >
    What am I missing here?
    >
    Thanks, Brad
    Without seeing your full code, i found that suggestion which may work
    for you:
    สล็อตเว็บตรง API แท้ ไม่ผ่านเอเย่นต์ เว็บสล็อตใหม่ล่าสุด ฝากถอนง่าย ผ่านทุกธนาคารในไทย เว็บตรง 100% เบทน้อยเล่นได้ ทุกที่ทุกเวลา


    Thanks,

    Onur Güzel

    Comment

    • Brad Pears

      #3
      Re: Unable to reference form field...

      Unfortunately that solution appears to be specific to ASP... I will jsut use
      a public variable for now but I'd like to get to the bottom of that issue...

      Thanks for the response...

      Brad

      "kimiraikko nen" <kimiraikkonen8 5@gmail.comwrot e in message
      news:555a68a2-69e7-450f-a359-15623166af31@p2 5g2000hsf.googl egroups.com...
      On Jun 3, 6:52 pm, "Brad Pears" <br...@truenort hloghomes.comwr ote:
      I have the following code that references a "textbox" on a form. I want to
      pass the value of this textbox to a stored procedure as a parameter. This
      code is located on a different form obviously. I thought that I would be
      able to reference the textbox simply by placing the name of the form it is
      located on (class name) in front as follows...
      >
      param1 = frmSteelPlates. txtJobNo.Text
      >
      I am getting the following error when I debug the line to see what the
      value
      of the text box actually is...
      >
      "Reference to a non-shared member requires an object reference"
      >
      What am I missing here?
      >
      Thanks, Brad
      Without seeing your full code, i found that suggestion which may work
      for you:
      สล็อตเว็บตรง API แท้ ไม่ผ่านเอเย่นต์ เว็บสล็อตใหม่ล่าสุด ฝากถอนง่าย ผ่านทุกธนาคารในไทย เว็บตรง 100% เบทน้อยเล่นได้ ทุกที่ทุกเวลา


      Thanks,

      Onur Güzel


      Comment

      • Jack Jackson

        #4
        Re: Unable to reference form field...

        On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
        <bradp@truenort hloghomes.comwr ote:
        >I have the following code that references a "textbox" on a form. I want to
        >pass the value of this textbox to a stored procedure as a parameter. This
        >code is located on a different form obviously. I thought that I would be
        >able to reference the textbox simply by placing the name of the form it is
        >located on (class name) in front as follows...
        >
        >param1 = frmSteelPlates. txtJobNo.Text
        >
        >I am getting the following error when I debug the line to see what the value
        >of the text box actually is...
        >
        >"Reference to a non-shared member requires an object reference"
        >
        >What am I missing here?
        >
        >Thanks, Brad
        >
        If frmSteelPlates is a reference to the other form, and if txtJobNo is
        marked Public, then it would work.

        My guess is that frmSteelPlates is a class name, not a reference to an
        instance of the class.

        I don't think it is good practice to make controls be Public and
        reference them from somewhere else. It ties the code too closely to
        how you chose to implement the form.

        I would add to the form that contains the textbox a Public Function
        that returns the value, something like:

        Public Function GetJobNo() As String
        Return txtJobNo.Text
        End Function

        Then arrange for the form that calls the stored procedure to have a
        reference to the form that has the job number.

        Comment

        • Brad Pears

          #5
          Re: Unable to reference form field...

          Ok, that sounds good. I will implement it like that instead. In teh meantime
          I decided to use a public variable (pJobNo) which works fine, but I prefer
          not to use them if there is a better method that is not too difficult of an
          implementation.

          Thanks, Brad

          "Jack Jackson" <jjackson@cinno vations.netwrot e in message
          news:n4va44tfch qcublvbk2ngcu14 kjasrrul5@4ax.c om...
          On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
          <bradp@truenort hloghomes.comwr ote:
          >
          >>I have the following code that references a "textbox" on a form. I want to
          >>pass the value of this textbox to a stored procedure as a parameter. This
          >>code is located on a different form obviously. I thought that I would be
          >>able to reference the textbox simply by placing the name of the form it is
          >>located on (class name) in front as follows...
          >>
          >>param1 = frmSteelPlates. txtJobNo.Text
          >>
          >>I am getting the following error when I debug the line to see what the
          >>value
          >>of the text box actually is...
          >>
          >>"Reference to a non-shared member requires an object reference"
          >>
          >>What am I missing here?
          >>
          >>Thanks, Brad
          >>
          >
          If frmSteelPlates is a reference to the other form, and if txtJobNo is
          marked Public, then it would work.
          >
          My guess is that frmSteelPlates is a class name, not a reference to an
          instance of the class.
          >
          I don't think it is good practice to make controls be Public and
          reference them from somewhere else. It ties the code too closely to
          how you chose to implement the form.
          >
          I would add to the form that contains the textbox a Public Function
          that returns the value, something like:
          >
          Public Function GetJobNo() As String
          Return txtJobNo.Text
          End Function
          >
          Then arrange for the form that calls the stored procedure to have a
          reference to the form that has the job number.

          Comment

          • Brad Pears

            #6
            Re: Unable to reference form field...

            One other quick question...

            When you said

            " Then arrange for the form that calls the stored procedure to have a
            reference to the form that has the job number."

            I'm just not sure what you mean there...

            Basically I want to call your function "GetJobNo" in a completely different
            form (the one that calls the stored procedure) than the one that fucntion
            "GetJobNo" was declared public in. I can't do that unless I pass the actual
            entire form by reference to the new form - is that what you mean?

            Could you give me a quick example of what you are referring to there?

            Thanks, Brad



            "Jack Jackson" <jjackson@cinno vations.netwrot e in message
            news:n4va44tfch qcublvbk2ngcu14 kjasrrul5@4ax.c om...
            On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
            <bradp@truenort hloghomes.comwr ote:
            >
            >>I have the following code that references a "textbox" on a form. I want to
            >>pass the value of this textbox to a stored procedure as a parameter. This
            >>code is located on a different form obviously. I thought that I would be
            >>able to reference the textbox simply by placing the name of the form it is
            >>located on (class name) in front as follows...
            >>
            >>param1 = frmSteelPlates. txtJobNo.Text
            >>
            >>I am getting the following error when I debug the line to see what the
            >>value
            >>of the text box actually is...
            >>
            >>"Reference to a non-shared member requires an object reference"
            >>
            >>What am I missing here?
            >>
            >>Thanks, Brad
            >>
            >
            If frmSteelPlates is a reference to the other form, and if txtJobNo is
            marked Public, then it would work.
            >
            My guess is that frmSteelPlates is a class name, not a reference to an
            instance of the class.
            >
            I don't think it is good practice to make controls be Public and
            reference them from somewhere else. It ties the code too closely to
            how you chose to implement the form.
            >
            I would add to the form that contains the textbox a Public Function
            that returns the value, something like:
            >
            Public Function GetJobNo() As String
            Return txtJobNo.Text
            End Function
            >
            Then arrange for the form that calls the stored procedure to have a
            reference to the form that has the job number.

            Comment

            • Jack Jackson

              #7
              Re: Unable to reference form field...

              Yes. You need a reference to the form that contains the textbox
              (saying "pass the actual entire form by reference" doesn't really mean
              anything, a reference is a pointer to the instantiation of the class).

              You can get the reference in a couple of ways. If the form with the
              textbox starts the other form, then it is easy. If the second form is
              a modal dialog box then you will have code like:

              Using frm2 As New Form2
              frm2.ShowDialog ()
              End Using

              To pass a reference to the calling form you can either pass it as a
              parameter to the form's New or call a method:

              Using frm2 As New Form2(Me)
              or
              Using frm2 As New Form2
              frm2.SetCalling Form(Me)
              frm2.ShowDialog ()
              End Using

              You could also look through the application's list of forms to find
              the form you want (System.Windows .Forms.Applicat ion.OpenForms).

              On Tue, 3 Jun 2008 17:01:49 -0400, "Brad Pears"
              <bradp@truenort hloghomes.comwr ote:
              >One other quick question...
              >
              >When you said
              >
              >" Then arrange for the form that calls the stored procedure to have a
              >reference to the form that has the job number."
              >
              >I'm just not sure what you mean there...
              >
              >Basically I want to call your function "GetJobNo" in a completely different
              >form (the one that calls the stored procedure) than the one that fucntion
              >"GetJobNo" was declared public in. I can't do that unless I pass the actual
              >entire form by reference to the new form - is that what you mean?
              >
              >Could you give me a quick example of what you are referring to there?
              >
              >Thanks, Brad
              >
              >
              >
              >"Jack Jackson" <jjackson@cinno vations.netwrot e in message
              >news:n4va44tfc hqcublvbk2ngcu1 4kjasrrul5@4ax. com...
              >On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
              ><bradp@truenor thloghomes.comw rote:
              >>
              >>>I have the following code that references a "textbox" on a form. I want to
              >>>pass the value of this textbox to a stored procedure as a parameter. This
              >>>code is located on a different form obviously. I thought that I would be
              >>>able to reference the textbox simply by placing the name of the form it is
              >>>located on (class name) in front as follows...
              >>>
              >>>param1 = frmSteelPlates. txtJobNo.Text
              >>>
              >>>I am getting the following error when I debug the line to see what the
              >>>value
              >>>of the text box actually is...
              >>>
              >>>"Reference to a non-shared member requires an object reference"
              >>>
              >>>What am I missing here?
              >>>
              >>>Thanks, Brad
              >>>
              >>
              >If frmSteelPlates is a reference to the other form, and if txtJobNo is
              >marked Public, then it would work.
              >>
              >My guess is that frmSteelPlates is a class name, not a reference to an
              >instance of the class.
              >>
              >I don't think it is good practice to make controls be Public and
              >reference them from somewhere else. It ties the code too closely to
              >how you chose to implement the form.
              >>
              >I would add to the form that contains the textbox a Public Function
              >that returns the value, something like:
              >>
              >Public Function GetJobNo() As String
              > Return txtJobNo.Text
              >End Function
              >>
              >Then arrange for the form that calls the stored procedure to have a
              >reference to the form that has the job number.
              >

              Comment

              • Cor Ligthert[MVP]

                #8
                Re: Unable to reference form field...

                Brad,

                A class is only a template, this is a little bit confusing for former VB6
                users, as in that language where AFAIK classes always shared classes, and
                therefore in fact modules.

                The form class is now a real class. And therefore you have to instance it
                from your current class to an obect.

                Therefore as you show us how you have instanced frmSteelPlates, then some of
                us can tell you probably more.

                (There are and endles quantity of methods to create an form object)

                Cor

                "Brad Pears" <bradp@truenort hloghomes.comsc hreef in bericht
                news:eB00PHZxIH A.4564@TK2MSFTN GP06.phx.gbl...
                >I have the following code that references a "textbox" on a form. I want to
                >pass the value of this textbox to a stored procedure as a parameter. This
                >code is located on a different form obviously. I thought that I would be
                >able to reference the textbox simply by placing the name of the form it is
                >located on (class name) in front as follows...
                >
                param1 = frmSteelPlates. txtJobNo.Text
                >
                I am getting the following error when I debug the line to see what the
                value of the text box actually is...
                >
                "Reference to a non-shared member requires an object reference"
                >
                What am I missing here?
                >
                Thanks, Brad
                >

                Comment

                • Joergen Bech

                  #9
                  Re: Unable to reference form field...

                  On Wed, 4 Jun 2008 05:40:36 +0200, "Cor Ligthert[MVP]"
                  <notmyfirstname @planet.nlwrote :
                  >Brad,
                  Cor,
                  >A class is only a template, this is a little bit confusing for former VB6
                  >users, as in that language where AFAIK classes always shared classes, and
                  >therefore in fact modules.
                  In VB6, a class must be stored in a single file and a single file
                  cannot contain more than one class. Still, except for the lack
                  of inheritance, classes in VB6 work pretty much like those in
                  VB.Net, albeit a little crippled by comparison.

                  A default instance of a form in VB6 can be referenced without
                  instantiation, but it is also possible to create multiple, non-default
                  instances of a form.
                  >The form class is now a real class. And therefore you have to instance it
                  >from your current class to an obect.
                  This was true in VS2002 and VS2003, but VS2005 (re)introduced
                  the default instance model known from VB6, so in VB.Net 2005+ it
                  is now possible to write

                  Sub main()
                  Form1.ShowDialo g()
                  End Sub

                  i.e. display the default instance of a form without declaring
                  it first. This is (now) handled behind the scenes.

                  If all you ever need is to display one instance of the same
                  form class at a time, the default instance can be used.

                  My personal opinion is that Microsoft never should have
                  added the default instance stuff but kept forcing developers
                  to keep things explicit, i.e. out in plain view. Less opportunity
                  for errors and confusion.
                  >Therefore as you show us how you have instanced frmSteelPlates, then some of
                  >us can tell you probably more.
                  I'll second that.

                  Regards,

                  Joergen Bech



                  Comment

                  • Brad Pears

                    #10
                    Re: Unable to reference form field...

                    Got it!!

                    I'm pretty new to this stuff...

                    Thanks, Brad

                    "Jack Jackson" <jjackson@cinno vations.netwrot e in message
                    news:epgb445q8r b9b0tefrc1kvniv uk3v1bci2@4ax.c om...
                    Yes. You need a reference to the form that contains the textbox
                    (saying "pass the actual entire form by reference" doesn't really mean
                    anything, a reference is a pointer to the instantiation of the class).
                    >
                    You can get the reference in a couple of ways. If the form with the
                    textbox starts the other form, then it is easy. If the second form is
                    a modal dialog box then you will have code like:
                    >
                    Using frm2 As New Form2
                    frm2.ShowDialog ()
                    End Using
                    >
                    To pass a reference to the calling form you can either pass it as a
                    parameter to the form's New or call a method:
                    >
                    Using frm2 As New Form2(Me)
                    or
                    Using frm2 As New Form2
                    frm2.SetCalling Form(Me)
                    frm2.ShowDialog ()
                    End Using
                    >
                    You could also look through the application's list of forms to find
                    the form you want (System.Windows .Forms.Applicat ion.OpenForms).
                    >
                    On Tue, 3 Jun 2008 17:01:49 -0400, "Brad Pears"
                    <bradp@truenort hloghomes.comwr ote:
                    >
                    >>One other quick question...
                    >>
                    >>When you said
                    >>
                    >>" Then arrange for the form that calls the stored procedure to have a
                    >>reference to the form that has the job number."
                    >>
                    >>I'm just not sure what you mean there...
                    >>
                    >>Basically I want to call your function "GetJobNo" in a completely
                    >>different
                    >>form (the one that calls the stored procedure) than the one that fucntion
                    >>"GetJobNo" was declared public in. I can't do that unless I pass the
                    >>actual
                    >>entire form by reference to the new form - is that what you mean?
                    >>
                    >>Could you give me a quick example of what you are referring to there?
                    >>
                    >>Thanks, Brad
                    >>
                    >>
                    >>
                    >>"Jack Jackson" <jjackson@cinno vations.netwrot e in message
                    >>news:n4va44tf chqcublvbk2ngcu 14kjasrrul5@4ax .com...
                    >>On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
                    >><bradp@trueno rthloghomes.com wrote:
                    >>>
                    >>>>I have the following code that references a "textbox" on a form. I want
                    >>>>to
                    >>>>pass the value of this textbox to a stored procedure as a parameter.
                    >>>>This
                    >>>>code is located on a different form obviously. I thought that I would be
                    >>>>able to reference the textbox simply by placing the name of the form it
                    >>>>is
                    >>>>located on (class name) in front as follows...
                    >>>>
                    >>>>param1 = frmSteelPlates. txtJobNo.Text
                    >>>>
                    >>>>I am getting the following error when I debug the line to see what the
                    >>>>value
                    >>>>of the text box actually is...
                    >>>>
                    >>>>"Referenc e to a non-shared member requires an object reference"
                    >>>>
                    >>>>What am I missing here?
                    >>>>
                    >>>>Thanks, Brad
                    >>>>
                    >>>
                    >>If frmSteelPlates is a reference to the other form, and if txtJobNo is
                    >>marked Public, then it would work.
                    >>>
                    >>My guess is that frmSteelPlates is a class name, not a reference to an
                    >>instance of the class.
                    >>>
                    >>I don't think it is good practice to make controls be Public and
                    >>reference them from somewhere else. It ties the code too closely to
                    >>how you chose to implement the form.
                    >>>
                    >>I would add to the form that contains the textbox a Public Function
                    >>that returns the value, something like:
                    >>>
                    >>Public Function GetJobNo() As String
                    >> Return txtJobNo.Text
                    >>End Function
                    >>>
                    >>Then arrange for the form that calls the stored procedure to have a
                    >>reference to the form that has the job number.
                    >>

                    Comment

                    Working...