Problems with programmatically added control - can't get properties, can't even reference control!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Just_a_fan@home.net

    #1

    Problems with programmatically added control - can't get properties, can't even reference control!

    I am adding a bunch of controls with the code below.

    Problem 1: When program flow passes to "UpperChang ed" when I click it,
    the control name is undefined. When I enter:

    If udUpperLim1.Val ue 1 Then

    I get an error that udUpperLim1 is "Not Defined" so I cannot get the
    value in the control.

    Problem 2: When I use sender.tostring , it returns the class name of the
    control, not its assigned name. I get
    "System.Windows .Forms.NumericU pDown" and not udUpperLim1 and I don't
    know who was changed and along with the preceding problem, even if I
    did, I can't reference it!

    The folks who decided to remove control arrays DID NOT DO US ANY
    FAVORS!!!!!!!!! !

    This is all straight out of a book and is not doing anything useful for
    me.

    Help, Please!

    Mike Morrow
    MSDN:MMSA00E625 37

    iTop = 84

    Dim udUpperLim1 As New NumericUpDown
    udUpperLim1.Set Bounds(228, iTop, 45, 20)
    iTop += 20
    Me.Controls.Add (udUpperLim1)
    AddHandler udUpperLim1.Val ueChanged, AddressOf UpperChanged
    udUpperLim1.Val ue = My.Settings.Ala rm1

    Dim udUpperLim3 As New NumericUpDown
    udUpperLim3.Set Bounds(228, iTop, 45, 20)
    iTop += 20
    Me.Controls.Add (udUpperLim3)
    AddHandler udUpperLim3.Val ueChanged, AddressOf UpperChanged
    udUpperLim3.Val ue = My.Settings.Ala rm3

    Dim udUpperLim5 As New NumericUpDown
    udUpperLim5.Set Bounds(228, iTop, 45, 20)
    iTop += 20
    Me.Controls.Add (udUpperLim5)
    AddHandler udUpperLim5.Val ueChanged, AddressOf UpperChanged
    udUpperLim5.Val ue = My.Settings.Ala rm5


  • Steve Gerrard

    #2
    Re: Problems with programmaticall y added control - can't get properties, can't even reference control!

    Just_a_fan@home .net wrote:
    I am adding a bunch of controls with the code below.
    >
    Problem 1: When program flow passes to "UpperChang ed" when I click it,
    the control name is undefined. When I enter:
    >
    If udUpperLim1.Val ue 1 Then
    >
    I get an error that udUpperLim1 is "Not Defined" so I cannot get the
    value in the control.
    >
    Problem 2: When I use sender.tostring , it returns the class name of
    the control, not its assigned name. I get
    "System.Windows .Forms.NumericU pDown" and not udUpperLim1 and I don't
    know who was changed and along with the preceding problem, even if I
    did, I can't reference it!
    >
    You need to discover the Name property of a control. :)

    It may seem silly, but it is not. Your udUpperLim1 variable is a temporary
    reference, and soon out of scope. You need to name the actual object. Add the
    control like this:

    Dim udUpperLim1 As New NumericUpDown
    udUpperLim1.Nam e = "udUpperLim 1"
    ' all the rest...

    If you need to get hold of it later, you can do
    Dim udUL As NumericUpDown
    udUL = TryCast(Me.Cont rols.Item("udUp perLim1"), NumericUpDown)
    if udUL IsNot Nothing Then
    ' got it...

    In an event handler, you can do the same thing:
    Dim udUL As NumericUpDown
    udUL = TryCast(sender, NumericUpDown)
    if udUL IsNot Nothing Then
    ' sender is a NumericUpDown
    If udUL.Name = "udUpperLim 1" Then
    ' it is that one...






    Comment

    • SneeKeeFahk

      #3
      Re: Problems with programmaticall y added control - can't get properties, can't even reference control!

      Problem 1: When program flow passes to "UpperChang ed" when I click it,
      the control name is undefined. When I enter:
      >
      If udUpperLim1.Val ue 1 Then
      >
      I get an error that udUpperLim1 is "Not Defined" so I cannot get the
      value in the control.
      This is because in your code your not giving the control an ID. Your naming
      the variable that is holding the control but not setting the ID property.

      Dim udUpperLim1 As New NumericUpDown
      '************** ************
      'Set the ID property of the control
      udUpperLim1.ID = "udUpperLim 1"
      '************** ************
      udUpperLim1.Set Bounds(228, iTop, 45, 20)
      iTop += 20
      Me.Controls.Add (udUpperLim1)
      AddHandler udUpperLim1.Val ueChanged, AddressOf UpperChanged
      udUpperLim1.Val ue = My.Settings.Ala rm1
      Problem 2: When I use sender.tostring , it returns the class name of the
      control, not its assigned name. I get
      "System.Windows .Forms.NumericU pDown" and not udUpperLim1 and I don't
      know who was changed and along with the preceding problem, even if I
      did, I can't reference it!
      This is because you are calling .ToString() which returns the objects type
      in a string ... try using sender.ID

      - Adam

      Comment

      • Lloyd Sheen

        #4
        Re: Problems with programmaticall y added control - can't get properties, can't even reference control!


        "SneeKeeFah k" <NOSPAM@DONTSPA M.comwrote in message
        news:uzYcifX2IH A.4140@TK2MSFTN GP03.phx.gbl...
        >Problem 1: When program flow passes to "UpperChang ed" when I click it,
        >the control name is undefined. When I enter:
        >>
        > If udUpperLim1.Val ue 1 Then
        >>
        >I get an error that udUpperLim1 is "Not Defined" so I cannot get the
        >value in the control.
        >
        This is because in your code your not giving the control an ID. Your
        naming the variable that is holding the control but not setting the ID
        property.
        >
        Dim udUpperLim1 As New NumericUpDown
        '************** ************
        'Set the ID property of the control
        udUpperLim1.ID = "udUpperLim 1"
        '************** ************
        udUpperLim1.Set Bounds(228, iTop, 45, 20)
        iTop += 20
        Me.Controls.Add (udUpperLim1)
        AddHandler udUpperLim1.Val ueChanged, AddressOf UpperChanged
        udUpperLim1.Val ue = My.Settings.Ala rm1
        >
        >Problem 2: When I use sender.tostring , it returns the class name of the
        >control, not its assigned name. I get
        >"System.Window s.Forms.Numeric UpDown" and not udUpperLim1 and I don't
        >know who was changed and along with the preceding problem, even if I
        >did, I can't reference it!
        >
        This is because you are calling .ToString() which returns the objects type
        in a string ... try using sender.ID
        >
        - Adam
        >
        If you are doing ASP use the ID property. If you are using winforms use the
        Name property.

        LS

        Comment

        • Cor Ligthert[MVP]

          #5
          Re: Problems with programmaticall y added control - can't get properties, can't even reference control!

          Mike,

          See my sample in your latter question. Be aware that as you drag a control
          on a form the ObjectName of the control is in ASPNET or Windowsforms always
          the ClassName extended with a number from one to n.

          Cor

          <Just_a_fan@hom e.netschreef in bericht
          news:b2fd64pk07 ica8kvt05t32avb bie3j8edv@4ax.c om...
          >I am adding a bunch of controls with the code below.
          >
          Problem 1: When program flow passes to "UpperChang ed" when I click it,
          the control name is undefined. When I enter:
          >
          If udUpperLim1.Val ue 1 Then
          >
          I get an error that udUpperLim1 is "Not Defined" so I cannot get the
          value in the control.
          >
          Problem 2: When I use sender.tostring , it returns the class name of the
          control, not its assigned name. I get
          "System.Windows .Forms.NumericU pDown" and not udUpperLim1 and I don't
          know who was changed and along with the preceding problem, even if I
          did, I can't reference it!
          >
          The folks who decided to remove control arrays DID NOT DO US ANY
          FAVORS!!!!!!!!! !
          >
          This is all straight out of a book and is not doing anything useful for
          me.
          >
          Help, Please!
          >
          Mike Morrow
          MSDN:MMSA00E625 37
          >
          iTop = 84
          >
          Dim udUpperLim1 As New NumericUpDown
          udUpperLim1.Set Bounds(228, iTop, 45, 20)
          iTop += 20
          Me.Controls.Add (udUpperLim1)
          AddHandler udUpperLim1.Val ueChanged, AddressOf UpperChanged
          udUpperLim1.Val ue = My.Settings.Ala rm1
          >
          Dim udUpperLim3 As New NumericUpDown
          udUpperLim3.Set Bounds(228, iTop, 45, 20)
          iTop += 20
          Me.Controls.Add (udUpperLim3)
          AddHandler udUpperLim3.Val ueChanged, AddressOf UpperChanged
          udUpperLim3.Val ue = My.Settings.Ala rm3
          >
          Dim udUpperLim5 As New NumericUpDown
          udUpperLim5.Set Bounds(228, iTop, 45, 20)
          iTop += 20
          Me.Controls.Add (udUpperLim5)
          AddHandler udUpperLim5.Val ueChanged, AddressOf UpperChanged
          udUpperLim5.Val ue = My.Settings.Ala rm5
          >
          >

          Comment

          • eBob.com

            #6
            Re: Problems with programmaticall y added control - can't get properties, can't even reference control!


            <Just_a_fan@hom e.netwrote in message
            news:b2fd64pk07 ica8kvt05t32avb bie3j8edv@4ax.c om...
            <snip>
            The folks who decided to remove control arrays DID NOT DO US ANY
            FAVORS!!!!!!!!! !
            <snip>
            Mike Morrow
            MSDN:MMSA00E625 37
            <snip>
            Hi Mike,

            When I saw the above statement in your post I thought that just couldn't be.
            Surely, I thought, arrays of controls are still possible. If not, I have a
            lot of code which is not going to work. But then I remembered, from another
            of your threads, that you are, like me, an old mainframer - so certainly a
            guy of superior intelligence. And I thought therefore I'd better see if
            "control arrays" are different from arrays of controls. So I did a search
            (using a VB Express which I downloaded just a few days ago) and found the
            following statement ...

            The BaseControlArra y class is the base class for all control arrays used in
            applications upgraded from Visual Basic 6.0.

            Having never used VB 6 and having never looked into BaseControlArra ys I may
            not fully understand it, but it looks like there might be some new and
            improved version of "control arrays" - whatever they were. And if control
            arrays are what I'd imagine them to be perhaps you could create an array of
            controls.

            ALSO, not sure what you are trying to do, but when I've needed to know
            something about a control which caused an event handler to be invoked (when
            one event handler is shared by many similar controls, I've used the Tag
            property. It's defined as an object so you can jam as much information into
            it as you need to.

            Are you an ex-mainframer or a current mainframer who also does .Net?

            SVC 3, Bob


            Comment

            • Just_a_fan@home.net

              #7
              Re: Re: Problems with programmaticall y added control - can't get properties, can't even reference control!

              I did DOS, DOS/VSE and a couple of variations of MVS during my time with
              big iron. Mostly assembler, some operating system support with heavy
              emphasis on assembler, machine language and REXX. I have known and work
              with about a dozen languages but have gone to PC stuff exclusively now.

              I have written a little to a lot in all of the following:

              1620 Fortran II (a little)
              1620 Assembler (a lot)
              Fortran IV (moderate)
              IBM Assembler (a lot)
              IBM Assembler Macro (a lot)
              Pascal (till I got tired of typing ";"s)
              Atari "Action" (well, I was broke at the time)
              C (a little)
              CLIST (moderate)
              REXX (a lot)
              Visual Basic 3-6 (a lot)
              Visual Basic.Net (becoming a lot, quite rapidly)

              I must have missed a few. I miss assembler and REXX the most. REXX did
              some stuff that nothing else did and made life easier.

              I remember reading about Array of Controls but cannot find anything in
              the index of my books. Going online.

              Mike

              On Sun, 29 Jun 2008 10:47:01 -0400, in
              microsoft.publi c.dotnet.langua ges.vb "eBob.com"
              <fakename@total lybogus.comwrot e:
              >
              ><Just_a_fan@ho me.netwrote in message
              >news:b2fd64pk0 7ica8kvt05t32av bbie3j8edv@4ax. com...
              > <snip>
              >The folks who decided to remove control arrays DID NOT DO US ANY
              >FAVORS!!!!!!!! !!
              ><snip>
              >Mike Morrow
              >MSDN:MMSA00E62 537
              ><snip>
              >
              >Hi Mike,
              >
              >When I saw the above statement in your post I thought that just couldn't be.
              >Surely, I thought, arrays of controls are still possible. If not, I have a
              >lot of code which is not going to work. But then I remembered, from another
              >of your threads, that you are, like me, an old mainframer - so certainly a
              >guy of superior intelligence. And I thought therefore I'd better see if
              >"control arrays" are different from arrays of controls. So I did a search
              >(using a VB Express which I downloaded just a few days ago) and found the
              >following statement ...
              >
              >The BaseControlArra y class is the base class for all control arrays used in
              >applications upgraded from Visual Basic 6.0.
              >
              >Having never used VB 6 and having never looked into BaseControlArra ys I may
              >not fully understand it, but it looks like there might be some new and
              >improved version of "control arrays" - whatever they were. And if control
              >arrays are what I'd imagine them to be perhaps you could create an array of
              >controls.
              >
              >ALSO, not sure what you are trying to do, but when I've needed to know
              >something about a control which caused an event handler to be invoked (when
              >one event handler is shared by many similar controls, I've used the Tag
              >property. It's defined as an object so you can jam as much information into
              >it as you need to.
              >
              >Are you an ex-mainframer or a current mainframer who also does .Net?
              >
              >SVC 3, Bob
              >

              Comment

              • Just_a_fan@home.net

                #8
                Re: Re: Problems with programmaticall y added control - can't get properties, can't even reference control!

                How can a control on the main form "go out of scope"?

                On Sat, 28 Jun 2008 16:31:38 -0700, in
                microsoft.publi c.dotnet.langua ges.vb "Steve Gerrard"
                <mynamehere@com cast.netwrote:
                >Just_a_fan@hom e.net wrote:
                >I am adding a bunch of controls with the code below.
                >>
                >Problem 1: When program flow passes to "UpperChang ed" when I click it,
                >the control name is undefined. When I enter:
                >>
                > If udUpperLim1.Val ue 1 Then
                >>
                >I get an error that udUpperLim1 is "Not Defined" so I cannot get the
                >value in the control.
                >>
                >Problem 2: When I use sender.tostring , it returns the class name of
                >the control, not its assigned name. I get
                >"System.Window s.Forms.Numeric UpDown" and not udUpperLim1 and I don't
                >know who was changed and along with the preceding problem, even if I
                >did, I can't reference it!
                >>
                >
                >You need to discover the Name property of a control. :)
                >
                >It may seem silly, but it is not. Your udUpperLim1 variable is a temporary
                >reference, and soon out of scope. You need to name the actual object. Add the
                >control like this:
                >
                Dim udUpperLim1 As New NumericUpDown
                udUpperLim1.Nam e = "udUpperLim 1"
                ' all the rest...
                >
                >If you need to get hold of it later, you can do
                Dim udUL As NumericUpDown
                udUL = TryCast(Me.Cont rols.Item("udUp perLim1"), NumericUpDown)
                if udUL IsNot Nothing Then
                ' got it...
                >
                >In an event handler, you can do the same thing:
                Dim udUL As NumericUpDown
                udUL = TryCast(sender, NumericUpDown)
                if udUL IsNot Nothing Then
                ' sender is a NumericUpDown
                If udUL.Name = "udUpperLim 1" Then
                ' it is that one...
                >
                >
                >
                >
                >

                Comment

                • Just_a_fan@home.net

                  #9
                  Re: Re: Problems with programmaticall y added control - can't get properties, can't even reference control!

                  OK. I had not run across this .ID stuff in the two books I have read so
                  far. That should help. Thanks.

                  On Sat, 28 Jun 2008 18:36:54 -0500, in
                  microsoft.publi c.dotnet.langua ges.vb "SneeKeeFah k" <NOSPAM@DONTSPA M.com>
                  wrote:
                  >Problem 1: When program flow passes to "UpperChang ed" when I click it,
                  >the control name is undefined. When I enter:
                  >>
                  > If udUpperLim1.Val ue 1 Then
                  >>
                  >I get an error that udUpperLim1 is "Not Defined" so I cannot get the
                  >value in the control.
                  >
                  >This is because in your code your not giving the control an ID. Your naming
                  >the variable that is holding the control but not setting the ID property.
                  >
                  Dim udUpperLim1 As New NumericUpDown
                  '************** ************
                  'Set the ID property of the control
                  udUpperLim1.ID = "udUpperLim 1"
                  '************** ************
                  udUpperLim1.Set Bounds(228, iTop, 45, 20)
                  iTop += 20
                  Me.Controls.Add (udUpperLim1)
                  AddHandler udUpperLim1.Val ueChanged, AddressOf UpperChanged
                  udUpperLim1.Val ue = My.Settings.Ala rm1
                  >
                  >Problem 2: When I use sender.tostring , it returns the class name of the
                  >control, not its assigned name. I get
                  >"System.Window s.Forms.Numeric UpDown" and not udUpperLim1 and I don't
                  >know who was changed and along with the preceding problem, even if I
                  >did, I can't reference it!
                  >
                  >This is because you are calling .ToString() which returns the objects type
                  >in a string ... try using sender.ID
                  >
                  >- Adam

                  Comment

                  • Stephany Young

                    #10
                    Re: Re: Problems with programmaticall y added control - can't get properties, can't even reference control!

                    You're really missing the point.

                    It is NOT the control on the form that is goes out of scope. It is your
                    LOCAL reference to the control that goes out of scope.

                    If you do not want your references to go out of scope then define them at a
                    higher level.

                    Public Class MyForm
                    Inherits Form

                    Private udUpperLim1 As NumericUpDown
                    Private udUpperLim3 As NumericUpDown
                    Private udUpperLim4 As NumericUpDown

                    Private Sub Me_Load(ByVal sender As Object, ByVal e As EventArgs)
                    Handles Me.Load

                    iTop = 84

                    udUpperLim1 = New NumericUpDown
                    udUpperLim1.Set Bounds(228, iTop, 45, 20)
                    iTop += 20
                    Me.Controls.Add (udUpperLim1)
                    AddHandler udUpperLim1.Val ueChanged, AddressOf UpperChanged
                    udUpperLim1.Val ue = My.Settings.Ala rm1

                    udUpperLim3 = New NumericUpDown
                    udUpperLim3.Set Bounds(228, iTop, 45, 20)
                    iTop += 20
                    Me.Controls.Add (udUpperLim3)
                    AddHandler udUpperLim3.Val ueChanged, AddressOf UpperChanged
                    udUpperLim3.Val ue = My.Settings.Ala rm3

                    udUpperLim5 = New NumericUpDown
                    udUpperLim5.Set Bounds(228, iTop, 45, 20)
                    iTop += 20
                    Me.Controls.Add (udUpperLim5)
                    AddHandler udUpperLim5.Val ueChanged, AddressOf UpperChanged
                    udUpperLim5.Val ue = My.Settings.Ala rm5

                    End Sub

                    Now, udUpperLim1, udUpperLim3 and udUpperLim5 can be referenced from
                    anywhere inside MyForm, and, in normal circumstances, will not go out of
                    scope until MyForm is 'disposed'.

                    If you look in the 'designer' code for a form you will see that this is
                    similar to the code generated by VS from the graphical designer.


                    <Just_a_fan@hom e.netwrote in message
                    news:mcdg64l4ef j2pbd58hiph569p 6gbj7pcju@4ax.c om...
                    How can a control on the main form "go out of scope"?
                    >
                    On Sat, 28 Jun 2008 16:31:38 -0700, in
                    microsoft.publi c.dotnet.langua ges.vb "Steve Gerrard"
                    <mynamehere@com cast.netwrote:
                    >
                    >>Just_a_fan@ho me.net wrote:
                    >>I am adding a bunch of controls with the code below.
                    >>>
                    >>Problem 1: When program flow passes to "UpperChang ed" when I click it,
                    >>the control name is undefined. When I enter:
                    >>>
                    >> If udUpperLim1.Val ue 1 Then
                    >>>
                    >>I get an error that udUpperLim1 is "Not Defined" so I cannot get the
                    >>value in the control.
                    >>>
                    >>Problem 2: When I use sender.tostring , it returns the class name of
                    >>the control, not its assigned name. I get
                    >>"System.Windo ws.Forms.Numeri cUpDown" and not udUpperLim1 and I don't
                    >>know who was changed and along with the preceding problem, even if I
                    >>did, I can't reference it!
                    >>>
                    >>
                    >>You need to discover the Name property of a control. :)
                    >>
                    >>It may seem silly, but it is not. Your udUpperLim1 variable is a temporary
                    >>reference, and soon out of scope. You need to name the actual object. Add
                    >>the
                    >>control like this:
                    >>
                    > Dim udUpperLim1 As New NumericUpDown
                    > udUpperLim1.Nam e = "udUpperLim 1"
                    > ' all the rest...
                    >>
                    >>If you need to get hold of it later, you can do
                    > Dim udUL As NumericUpDown
                    > udUL = TryCast(Me.Cont rols.Item("udUp perLim1"), NumericUpDown)
                    > if udUL IsNot Nothing Then
                    > ' got it...
                    >>
                    >>In an event handler, you can do the same thing:
                    > Dim udUL As NumericUpDown
                    > udUL = TryCast(sender, NumericUpDown)
                    > if udUL IsNot Nothing Then
                    > ' sender is a NumericUpDown
                    > If udUL.Name = "udUpperLim 1" Then
                    > ' it is that one...
                    >>
                    >>
                    >>
                    >>
                    >>
                    >

                    Comment

                    • Just_a_fan@home.net

                      #11
                      Re: Re: Re: Problems with programmaticall y added control - can't get properties, can't even reference control!

                      I will do as you say. However, it looks like it is being defined twice.
                      When I get to a stopping point, I will certainly try this all out and be
                      ready to use it next time.

                      Thanks,
                      Mike

                      On Mon, 30 Jun 2008 14:19:42 +1200, in
                      microsoft.publi c.dotnet.langua ges.vb "Stephany Young" <noone@localhos t>
                      wrote:
                      >You're really missing the point.
                      >
                      >It is NOT the control on the form that is goes out of scope. It is your
                      >LOCAL reference to the control that goes out of scope.
                      >
                      >If you do not want your references to go out of scope then define them at a
                      >higher level.
                      >
                      Public Class MyForm
                      Inherits Form
                      >
                      Private udUpperLim1 As NumericUpDown
                      Private udUpperLim3 As NumericUpDown
                      Private udUpperLim4 As NumericUpDown
                      >
                      Private Sub Me_Load(ByVal sender As Object, ByVal e As EventArgs)
                      >Handles Me.Load
                      >
                      iTop = 84
                      >
                      udUpperLim1 = New NumericUpDown
                      udUpperLim1.Set Bounds(228, iTop, 45, 20)
                      iTop += 20
                      Me.Controls.Add (udUpperLim1)
                      AddHandler udUpperLim1.Val ueChanged, AddressOf UpperChanged
                      udUpperLim1.Val ue = My.Settings.Ala rm1
                      >
                      udUpperLim3 = New NumericUpDown
                      udUpperLim3.Set Bounds(228, iTop, 45, 20)
                      iTop += 20
                      Me.Controls.Add (udUpperLim3)
                      AddHandler udUpperLim3.Val ueChanged, AddressOf UpperChanged
                      udUpperLim3.Val ue = My.Settings.Ala rm3
                      >
                      udUpperLim5 = New NumericUpDown
                      udUpperLim5.Set Bounds(228, iTop, 45, 20)
                      iTop += 20
                      Me.Controls.Add (udUpperLim5)
                      AddHandler udUpperLim5.Val ueChanged, AddressOf UpperChanged
                      udUpperLim5.Val ue = My.Settings.Ala rm5
                      >
                      End Sub
                      >
                      >Now, udUpperLim1, udUpperLim3 and udUpperLim5 can be referenced from
                      >anywhere inside MyForm, and, in normal circumstances, will not go out of
                      >scope until MyForm is 'disposed'.
                      >
                      >If you look in the 'designer' code for a form you will see that this is
                      >similar to the code generated by VS from the graphical designer.
                      >
                      >
                      ><Just_a_fan@ho me.netwrote in message
                      >news:mcdg64l4e fj2pbd58hiph569 p6gbj7pcju@4ax. com...
                      >How can a control on the main form "go out of scope"?
                      >>
                      >On Sat, 28 Jun 2008 16:31:38 -0700, in
                      >microsoft.publ ic.dotnet.langu ages.vb "Steve Gerrard"
                      ><mynamehere@co mcast.netwrote:
                      >>
                      >>>Just_a_fan@h ome.net wrote:
                      >>>I am adding a bunch of controls with the code below.
                      >>>>
                      >>>Problem 1: When program flow passes to "UpperChang ed" when I click it,
                      >>>the control name is undefined. When I enter:
                      >>>>
                      >>> If udUpperLim1.Val ue 1 Then
                      >>>>
                      >>>I get an error that udUpperLim1 is "Not Defined" so I cannot get the
                      >>>value in the control.
                      >>>>
                      >>>Problem 2: When I use sender.tostring , it returns the class name of
                      >>>the control, not its assigned name. I get
                      >>>"System.Wind ows.Forms.Numer icUpDown" and not udUpperLim1 and I don't
                      >>>know who was changed and along with the preceding problem, even if I
                      >>>did, I can't reference it!
                      >>>>
                      >>>
                      >>>You need to discover the Name property of a control. :)
                      >>>
                      >>>It may seem silly, but it is not. Your udUpperLim1 variable is a temporary
                      >>>reference, and soon out of scope. You need to name the actual object. Add
                      >>>the
                      >>>control like this:
                      >>>
                      >> Dim udUpperLim1 As New NumericUpDown
                      >> udUpperLim1.Nam e = "udUpperLim 1"
                      >> ' all the rest...
                      >>>
                      >>>If you need to get hold of it later, you can do
                      >> Dim udUL As NumericUpDown
                      >> udUL = TryCast(Me.Cont rols.Item("udUp perLim1"), NumericUpDown)
                      >> if udUL IsNot Nothing Then
                      >> ' got it...
                      >>>
                      >>>In an event handler, you can do the same thing:
                      >> Dim udUL As NumericUpDown
                      >> udUL = TryCast(sender, NumericUpDown)
                      >> if udUL IsNot Nothing Then
                      >> ' sender is a NumericUpDown
                      >> If udUL.Name = "udUpperLim 1" Then
                      >> ' it is that one...
                      >>>
                      >>>
                      >>>
                      >>>
                      >>>
                      >>

                      Comment

                      • Chris Dunaway

                        #12
                        Re: Problems with programmaticall y added control - can't getproperties, can't even reference control!

                        On Jun 29, 8:18 pm, Just_a_...@home .net wrote:
                        I remember reading about Array of Controls but cannot find anything in
                        the index of my books. Going online.
                        Control arrays as they existed in VB6 do not exist in VB.Net. That
                        is, there is not a index property for a control and the IDE will not
                        create the array automatically if you give a control the same name as
                        an existing one.

                        However, you can create an array of controls just like you would
                        create an array of integers or an array of strings:

                        Dim MyControls(12) As Control 'An array of 13 controls

                        If you wish to be more specific:

                        Dim MyTextBoxes(12) As TextBox 'An array of 13 text boxes

                        To assign objects to the arrays, you can use controls that already
                        exist on the form:

                        MyTextBoxes(0) = Form1.TextBox1
                        MyTextBoxes(1) = Form1.TextBox2
                        'etc.

                        Or you can create new controls:

                        MyTextBoxes(0) = New TextBox()
                        MyTextBoxes(1) = New TextBox()

                        Then you can wire up their events:

                        AddHandler MyTextBoxes(0). TextChanged, AddressOf Text_TextChange d
                        AddHandler MyTextBoxes(1). TextChanged, AddressOf Text_TextChange d

                        And then in the TextChanged event, you can work with the textbox:

                        Private Sub Text_TextChange d(ByVal sender As Object, ByVal e As
                        System.EventArg s)
                        Dim tmpTextBox As TextBox = DirectCast(send er, TextBox) 'Get a
                        reference to the textbox that whose text changed

                        MsgBox(tmpTextB ox.Text) 'display its text
                        End Sub

                        Chris

                        Comment

                        • eBob.com

                          #13
                          Re: Re: Problems with programmaticall y added control - can't get properties, can't even reference control!


                          <Just_a_fan@hom e.netwrote in message
                          news:uicg64pip5 55bgiqb6f7k2vvd vl0dv3e0i@4ax.c om...
                          ... snip ...
                          I remember reading about Array of Controls but cannot find anything in
                          the index of my books. Going online.
                          >
                          Mike
                          >
                          I didn't mean Array of Controls, I meant array of controls. I.E.

                          Dim whatever() as TextBox

                          just like Dim whatever() as String.

                          Bob


                          Comment

                          • Cor Ligthert [MVP]

                            #14
                            Re: Problems with programmaticall y added control - can't get properties, can't even reference control!

                            Bob,

                            What do you mean by a mainframe.

                            I assume you are talking about non event driven programming, Be aware that
                            it is mostly something inherited from the puchcard time.

                            Most moderen programming is done by handling events raised by humans (wm
                            messages). Although I am at the moment busy with a project that is batch
                            processing, the same as in the punchcard time, beside a start I don't need
                            any events raised by humans.

                            However, as you are interacting with humans, on whatever device then you
                            need events to fullfil the way an user expects a program is working in this
                            milenium.

                            An event is (as it has to be used) always bound to a method which handles
                            the event. It is in fact very simple but mostly very difficult described.
                            In C# the call they first make a delegate (simple a let say in mainframe
                            terminology a reference to a program address where the method starts), and
                            then invoke that address (the delegate).

                            The advance from VB is that is has more less semi hardware solutions.

                            Cor

                            "eBob.com" <fakename@total lybogus.comschr eef in bericht
                            news:u2thAcf2IH A.2384@TK2MSFTN GP04.phx.gbl...
                            >
                            <Just_a_fan@hom e.netwrote in message
                            news:b2fd64pk07 ica8kvt05t32avb bie3j8edv@4ax.c om...
                            > <snip>
                            >The folks who decided to remove control arrays DID NOT DO US ANY
                            >FAVORS!!!!!!!! !!
                            ><snip>
                            >Mike Morrow
                            >MSDN:MMSA00E62 537
                            ><snip>
                            >
                            Hi Mike,
                            >
                            When I saw the above statement in your post I thought that just couldn't
                            be. Surely, I thought, arrays of controls are still possible. If not, I
                            have a lot of code which is not going to work. But then I remembered,
                            from another of your threads, that you are, like me, an old mainframer -
                            so certainly a guy of superior intelligence. And I thought therefore I'd
                            better see if "control arrays" are different from arrays of controls. So
                            I did a search (using a VB Express which I downloaded just a few days ago)
                            and found the following statement ...
                            >
                            The BaseControlArra y class is the base class for all control arrays used
                            in applications upgraded from Visual Basic 6.0.
                            >
                            Having never used VB 6 and having never looked into BaseControlArra ys I
                            may not fully understand it, but it looks like there might be some new and
                            improved version of "control arrays" - whatever they were. And if
                            control arrays are what I'd imagine them to be perhaps you could create an
                            array of controls.
                            >
                            ALSO, not sure what you are trying to do, but when I've needed to know
                            something about a control which caused an event handler to be invoked
                            (when one event handler is shared by many similar controls, I've used the
                            Tag property. It's defined as an object so you can jam as much
                            information into it as you need to.
                            >
                            Are you an ex-mainframer or a current mainframer who also does .Net?
                            >
                            SVC 3, Bob
                            >

                            Comment

                            Working...