Newbie question: Indexing through control array


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Newbie question: Indexing through control array

  1. #1
    FG Guest

    Newbie question: Indexing through control array


    Hello,
    I'm a newbie trying to write an application that uses a control array of
    text boxes. I would like to fill the boxes with values I am receiving from
    the comm port. So far so good on that. My problem is that I would like
    for the user to be able to click on a text box and then when the value comes
    across the comm port to have it fill that text box and advance to the next
    box in the array. Conceptually it seems simple enough to me, but I can't
    get the code to work. I would appreciate any suggestions or code. Thanks
    in advance.
    Fred

  2. #2
    Rick Rothstein Guest

    Re: Newbie question: Indexing through control array

    This is untested, top-of-the-head code so you may have to play around with
    it a little. Here I'm assuming your TextBox control array is named Text1 and
    that your control array indexes are sequentially numbered:

    Indx = 0
    For X = Text1.LBound To Text1.UBound
    Text1(Indx).Text = GetCommPortDateFunction()
    Indx = Indx + 1
    If I > Text1.UBound Then I = Text1.LBound
    Text1(Indx).SetFocus
    Next

    where the GetCommPortDateFunction is meant to be the method you are using to
    get the comm port data.

    Rick


    "FG" <ztgjek@aol.com> wrote in message news:39484790$1@news.devx.com...
    >
    > Hello,
    > I'm a newbie trying to write an application that uses a control array of
    > text boxes. I would like to fill the boxes with values I am receiving

    from
    > the comm port. So far so good on that. My problem is that I would like
    > for the user to be able to click on a text box and then when the value

    comes
    > across the comm port to have it fill that text box and advance to the next
    > box in the array. Conceptually it seems simple enough to me, but I can't
    > get the code to work. I would appreciate any suggestions or code. Thanks
    > in advance.
    > Fred




  3. #3
    FG Guest

    Re: Newbie question: Indexing through control array


    Rick,
    Your code will work for sequencing through the array starting at 0, but
    I would like for the user to be able to set the focus on any text box, have
    the value fill in and then index from that spot. I would also like it to
    be flexible enough to repeat this "jumping focus" and then continuing if
    the user wants.
    Thanks
    Fred

    "Rick Rothstein" <rick_newsgroup@email.com> wrote:
    >This is untested, top-of-the-head code so you may have to play around with
    >it a little. Here I'm assuming your TextBox control array is named Text1

    and
    >that your control array indexes are sequentially numbered:
    >
    >Indx = 0
    >For X = Text1.LBound To Text1.UBound
    > Text1(Indx).Text = GetCommPortDateFunction()
    > Indx = Indx + 1
    > If I > Text1.UBound Then I = Text1.LBound
    > Text1(Indx).SetFocus
    >Next
    >
    >where the GetCommPortDateFunction is meant to be the method you are using

    to
    >get the comm port data.
    >
    >Rick
    >
    >
    >"FG" <ztgjek@aol.com> wrote in message news:39484790$1@news.devx.com...
    >>
    >> Hello,
    >> I'm a newbie trying to write an application that uses a control array

    of
    >> text boxes. I would like to fill the boxes with values I am receiving

    >from
    >> the comm port. So far so good on that. My problem is that I would like
    >> for the user to be able to click on a text box and then when the value

    >comes
    >> across the comm port to have it fill that text box and advance to the

    next
    >> box in the array. Conceptually it seems simple enough to me, but I can't
    >> get the code to work. I would appreciate any suggestions or code. Thanks
    >> in advance.
    >> Fred

    >
    >



  4. #4
    Rick Rothstein Guest

    Re: Newbie question: Indexing through control array

    If you remove the Indx = 0 statement, the code should let you start at any
    TextBox and cycle though them starting with that one. That line was included
    to let you set the initial focus position. Removing that line and setting
    focus by any means you want should be acceptable. The

    If I > Text1.UBound Then I = Text1.LBound

    statement insures that the focus will wrap properly at the "last" TextBox
    which is why you should be able to start with any TextBox you want.

    I am not sure exactly what you mean by "flexible enough to repeat this
    'jumping focus' and then continue"?

    Rick


    "FG" <ztgjek@aol.com> wrote in message news:3948adc0$1@news.devx.com...
    >
    > Rick,
    > Your code will work for sequencing through the array starting at 0, but
    > I would like for the user to be able to set the focus on any text box,

    have
    > the value fill in and then index from that spot. I would also like it to
    > be flexible enough to repeat this "jumping focus" and then continuing if
    > the user wants.
    > Thanks
    > Fred
    >
    > "Rick Rothstein" <rick_newsgroup@email.com> wrote:
    > >This is untested, top-of-the-head code so you may have to play around

    with
    > >it a little. Here I'm assuming your TextBox control array is named Text1

    > and
    > >that your control array indexes are sequentially numbered:
    > >
    > >Indx = 0
    > >For X = Text1.LBound To Text1.UBound
    > > Text1(Indx).Text = GetCommPortDateFunction()
    > > Indx = Indx + 1
    > > If I > Text1.UBound Then I = Text1.LBound
    > > Text1(Indx).SetFocus
    > >Next
    > >
    > >where the GetCommPortDateFunction is meant to be the method you are using

    > to
    > >get the comm port data.
    > >
    > >Rick
    > >
    > >
    > >"FG" <ztgjek@aol.com> wrote in message news:39484790$1@news.devx.com...
    > >>
    > >> Hello,
    > >> I'm a newbie trying to write an application that uses a control array

    > of
    > >> text boxes. I would like to fill the boxes with values I am receiving

    > >from
    > >> the comm port. So far so good on that. My problem is that I would

    like
    > >> for the user to be able to click on a text box and then when the value

    > >comes
    > >> across the comm port to have it fill that text box and advance to the

    > next
    > >> box in the array. Conceptually it seems simple enough to me, but I

    can't
    > >> get the code to work. I would appreciate any suggestions or code.

    Thanks
    > >> in advance.
    > >> Fred

    > >
    > >

    >




  5. #5
    FG Guest

    Re: Newbie question: Indexing through control array


    Rick,
    I still have a few questions. For one, is Indx just a procedure level
    interger variable? or something else? Second I coded your example and still
    can't get it to index from the box that has focus.

    Private Sub Command1_Click()
    For X = Text1.LBound To Text1.UBound
    Text1(indx).Text = Text2.Text 'Instead of the sub
    indx = indx + 1
    If i > Text1.UBound Then
    i = Text1.LBound
    Text1(indx).SetFocus
    End If
    Next X

    End Sub

    Lastly, the code as written fills all of the array with the text2.text value.
    Sorry if I'm not getting the picture, please bare with me.
    Fred




    "Rick Rothstein" <rick_newsgroup@email.com> wrote:
    >If you remove the Indx = 0 statement, the code should let you start at any
    >TextBox and cycle though them starting with that one. That line was included
    >to let you set the initial focus position. Removing that line and setting
    >focus by any means you want should be acceptable. The
    >
    > If I > Text1.UBound Then I = Text1.LBound
    >
    >statement insures that the focus will wrap properly at the "last" TextBox
    >which is why you should be able to start with any TextBox you want.
    >
    >I am not sure exactly what you mean by "flexible enough to repeat this
    >'jumping focus' and then continue"?
    >
    >Rick
    >
    >
    >"FG" <ztgjek@aol.com> wrote in message news:3948adc0$1@news.devx.com...
    >>
    >> Rick,
    >> Your code will work for sequencing through the array starting at 0,

    but
    >> I would like for the user to be able to set the focus on any text box,

    >have
    >> the value fill in and then index from that spot. I would also like it

    to
    >> be flexible enough to repeat this "jumping focus" and then continuing

    if
    >> the user wants.
    >> Thanks
    >> Fred
    >>
    >> "Rick Rothstein" <rick_newsgroup@email.com> wrote:
    >> >This is untested, top-of-the-head code so you may have to play around

    >with
    >> >it a little. Here I'm assuming your TextBox control array is named Text1

    >> and
    >> >that your control array indexes are sequentially numbered:
    >> >
    >> >Indx = 0
    >> >For X = Text1.LBound To Text1.UBound
    >> > Text1(Indx).Text = GetCommPortDateFunction()
    >> > Indx = Indx + 1
    >> > If I > Text1.UBound Then I = Text1.LBound
    >> > Text1(Indx).SetFocus
    >> >Next
    >> >
    >> >where the GetCommPortDateFunction is meant to be the method you are using

    >> to
    >> >get the comm port data.
    >> >
    >> >Rick
    >> >
    >> >
    >> >"FG" <ztgjek@aol.com> wrote in message news:39484790$1@news.devx.com...
    >> >>
    >> >> Hello,
    >> >> I'm a newbie trying to write an application that uses a control array

    >> of
    >> >> text boxes. I would like to fill the boxes with values I am receiving
    >> >from
    >> >> the comm port. So far so good on that. My problem is that I would

    >like
    >> >> for the user to be able to click on a text box and then when the value
    >> >comes
    >> >> across the comm port to have it fill that text box and advance to the

    >> next
    >> >> box in the array. Conceptually it seems simple enough to me, but I

    >can't
    >> >> get the code to work. I would appreciate any suggestions or code.

    >Thanks
    >> >> in advance.
    >> >> Fred
    >> >
    >> >

    >>

    >
    >



  6. #6
    Rick Rothstein Guest

    Re: Newbie question: Indexing through control array

    The first thing you have to remember is that anyone answering a posted
    question does not know exactly what is going on at the posters computer. So
    we take guesses at to what we think is going on. My guess was that as an
    individual piece of data came into the comm port, it would be assigned to a
    TextBox and then the focus would be moved to the next TextBox. That is why I
    offered

    Text1(Indx).Text = GetCommPortDateFunction()

    as the first statement *inside* the For-Next loop. The idea was that however
    you receive the comm port data (one piece at a time), it would be done on
    each loop of the For-Next loop (one piece of data per loop) and assigned
    immediately to the TextBox having focus. The GetCommPortDateFunction()
    function's name was supposed to imply that to you (although I just now see I
    put Date instead of Data in the name). When you changed that implied
    function call to Text2.Text, then you told the routine to loop through all
    the TextBox(es) and immediately assign whatever is in Text2. There was no
    attempt to get a new piece of comm port data on each loop any more.

    As to the scope of the Indx variable -- I intended it to be local to where
    the routine was posted, but that is not an absolute. Again, it depends on
    what your code is doing and how it is doing it. Remember, the best I could
    do is guess at your particular situation.

    If you are receiving all your data to be displayed *first*, in one chunk,
    and then dividing it up into pieces for display, then you would replace the

    Text1(Indx).Text = GetCommPortDateFunction()

    statement with some sort of code that grabbed the appropriate piece of data
    on each loop of the For-Next loop. Again, hard for me to know what is going
    on at your place. If you are still having trouble implementing my suggested
    code, you will have to provide a lot more detail explaining how your code is
    structured. Maybe even posting your code itself (providing it is not too
    lengthy).

    Rick


    "FG" <ztgjek@aol.com> wrote in message news:3948eecd@news.devx.com...
    >
    > Rick,
    > I still have a few questions. For one, is Indx just a procedure level
    > interger variable? or something else? Second I coded your example and

    still
    > can't get it to index from the box that has focus.
    >
    > Private Sub Command1_Click()
    > For X = Text1.LBound To Text1.UBound
    > Text1(indx).Text = Text2.Text 'Instead of the sub
    > indx = indx + 1
    > If i > Text1.UBound Then
    > i = Text1.LBound
    > Text1(indx).SetFocus
    > End If
    > Next X
    >
    > End Sub
    >
    > Lastly, the code as written fills all of the array with the text2.text

    value.
    > Sorry if I'm not getting the picture, please bare with me.
    > Fred
    >
    >
    >
    >
    > "Rick Rothstein" <rick_newsgroup@email.com> wrote:
    > >If you remove the Indx = 0 statement, the code should let you start at

    any
    > >TextBox and cycle though them starting with that one. That line was

    included
    > >to let you set the initial focus position. Removing that line and setting
    > >focus by any means you want should be acceptable. The
    > >
    > > If I > Text1.UBound Then I = Text1.LBound
    > >
    > >statement insures that the focus will wrap properly at the "last" TextBox
    > >which is why you should be able to start with any TextBox you want.
    > >
    > >I am not sure exactly what you mean by "flexible enough to repeat this
    > >'jumping focus' and then continue"?
    > >
    > >Rick
    > >
    > >
    > >"FG" <ztgjek@aol.com> wrote in message news:3948adc0$1@news.devx.com...
    > >>
    > >> Rick,
    > >> Your code will work for sequencing through the array starting at 0,

    > but
    > >> I would like for the user to be able to set the focus on any text box,

    > >have
    > >> the value fill in and then index from that spot. I would also like it

    > to
    > >> be flexible enough to repeat this "jumping focus" and then continuing

    > if
    > >> the user wants.
    > >> Thanks
    > >> Fred
    > >>
    > >> "Rick Rothstein" <rick_newsgroup@email.com> wrote:
    > >> >This is untested, top-of-the-head code so you may have to play around

    > >with
    > >> >it a little. Here I'm assuming your TextBox control array is named

    Text1
    > >> and
    > >> >that your control array indexes are sequentially numbered:
    > >> >
    > >> >Indx = 0
    > >> >For X = Text1.LBound To Text1.UBound
    > >> > Text1(Indx).Text = GetCommPortDateFunction()
    > >> > Indx = Indx + 1
    > >> > If I > Text1.UBound Then I = Text1.LBound
    > >> > Text1(Indx).SetFocus
    > >> >Next
    > >> >
    > >> >where the GetCommPortDateFunction is meant to be the method you are

    using
    > >> to
    > >> >get the comm port data.
    > >> >
    > >> >Rick
    > >> >
    > >> >
    > >> >"FG" <ztgjek@aol.com> wrote in message

    news:39484790$1@news.devx.com...
    > >> >>
    > >> >> Hello,
    > >> >> I'm a newbie trying to write an application that uses a control

    array
    > >> of
    > >> >> text boxes. I would like to fill the boxes with values I am

    receiving
    > >> >from
    > >> >> the comm port. So far so good on that. My problem is that I would

    > >like
    > >> >> for the user to be able to click on a text box and then when the

    value
    > >> >comes
    > >> >> across the comm port to have it fill that text box and advance to

    the
    > >> next
    > >> >> box in the array. Conceptually it seems simple enough to me, but I

    > >can't
    > >> >> get the code to work. I would appreciate any suggestions or code.

    > >Thanks
    > >> >> in advance.
    > >> >> Fred
    > >> >
    > >> >
    > >>

    > >
    > >

    >




  7. #7
    FG Guest

    Re: Newbie question: Indexing through control array


    Thanks, I see what your saying.
    Fred


    "Rick Rothstein" <rick_newsgroup@email.com> wrote:
    >The first thing you have to remember is that anyone answering a posted
    >question does not know exactly what is going on at the posters computer.

    So
    >we take guesses at to what we think is going on. My guess was that as an
    >individual piece of data came into the comm port, it would be assigned to

    a
    >TextBox and then the focus would be moved to the next TextBox. That is why

    I
    >offered
    >
    > Text1(Indx).Text = GetCommPortDateFunction()
    >
    >as the first statement *inside* the For-Next loop. The idea was that however
    >you receive the comm port data (one piece at a time), it would be done on
    >each loop of the For-Next loop (one piece of data per loop) and assigned
    >immediately to the TextBox having focus. The GetCommPortDateFunction()
    >function's name was supposed to imply that to you (although I just now see

    I
    >put Date instead of Data in the name). When you changed that implied
    >function call to Text2.Text, then you told the routine to loop through all
    >the TextBox(es) and immediately assign whatever is in Text2. There was no
    >attempt to get a new piece of comm port data on each loop any more.
    >
    >As to the scope of the Indx variable -- I intended it to be local to where
    >the routine was posted, but that is not an absolute. Again, it depends on
    >what your code is doing and how it is doing it. Remember, the best I could
    >do is guess at your particular situation.
    >
    >If you are receiving all your data to be displayed *first*, in one chunk,
    >and then dividing it up into pieces for display, then you would replace

    the
    >
    > Text1(Indx).Text = GetCommPortDateFunction()
    >
    >statement with some sort of code that grabbed the appropriate piece of data
    >on each loop of the For-Next loop. Again, hard for me to know what is going
    >on at your place. If you are still having trouble implementing my suggested
    >code, you will have to provide a lot more detail explaining how your code

    is
    >structured. Maybe even posting your code itself (providing it is not too
    >lengthy).
    >
    >Rick
    >
    >
    >"FG" <ztgjek@aol.com> wrote in message news:3948eecd@news.devx.com...
    >>
    >> Rick,
    >> I still have a few questions. For one, is Indx just a procedure level
    >> interger variable? or something else? Second I coded your example and

    >still
    >> can't get it to index from the box that has focus.
    >>
    >> Private Sub Command1_Click()
    >> For X = Text1.LBound To Text1.UBound
    >> Text1(indx).Text = Text2.Text 'Instead of the sub
    >> indx = indx + 1
    >> If i > Text1.UBound Then
    >> i = Text1.LBound
    >> Text1(indx).SetFocus
    >> End If
    >> Next X
    >>
    >> End Sub
    >>
    >> Lastly, the code as written fills all of the array with the text2.text

    >value.
    >> Sorry if I'm not getting the picture, please bare with me.
    >> Fred
    >>
    >>
    >>
    >>
    >> "Rick Rothstein" <rick_newsgroup@email.com> wrote:
    >> >If you remove the Indx = 0 statement, the code should let you start at

    >any
    >> >TextBox and cycle though them starting with that one. That line was

    >included
    >> >to let you set the initial focus position. Removing that line and setting
    >> >focus by any means you want should be acceptable. The
    >> >
    >> > If I > Text1.UBound Then I = Text1.LBound
    >> >
    >> >statement insures that the focus will wrap properly at the "last" TextBox
    >> >which is why you should be able to start with any TextBox you want.
    >> >
    >> >I am not sure exactly what you mean by "flexible enough to repeat this
    >> >'jumping focus' and then continue"?
    >> >
    >> >Rick
    >> >
    >> >
    >> >"FG" <ztgjek@aol.com> wrote in message news:3948adc0$1@news.devx.com...
    >> >>
    >> >> Rick,
    >> >> Your code will work for sequencing through the array starting at

    0,
    >> but
    >> >> I would like for the user to be able to set the focus on any text box,
    >> >have
    >> >> the value fill in and then index from that spot. I would also like

    it
    >> to
    >> >> be flexible enough to repeat this "jumping focus" and then continuing

    >> if
    >> >> the user wants.
    >> >> Thanks
    >> >> Fred
    >> >>
    >> >> "Rick Rothstein" <rick_newsgroup@email.com> wrote:
    >> >> >This is untested, top-of-the-head code so you may have to play around
    >> >with
    >> >> >it a little. Here I'm assuming your TextBox control array is named

    >Text1
    >> >> and
    >> >> >that your control array indexes are sequentially numbered:
    >> >> >
    >> >> >Indx = 0
    >> >> >For X = Text1.LBound To Text1.UBound
    >> >> > Text1(Indx).Text = GetCommPortDateFunction()
    >> >> > Indx = Indx + 1
    >> >> > If I > Text1.UBound Then I = Text1.LBound
    >> >> > Text1(Indx).SetFocus
    >> >> >Next
    >> >> >
    >> >> >where the GetCommPortDateFunction is meant to be the method you are

    >using
    >> >> to
    >> >> >get the comm port data.
    >> >> >
    >> >> >Rick
    >> >> >
    >> >> >
    >> >> >"FG" <ztgjek@aol.com> wrote in message

    >news:39484790$1@news.devx.com...
    >> >> >>
    >> >> >> Hello,
    >> >> >> I'm a newbie trying to write an application that uses a control

    >array
    >> >> of
    >> >> >> text boxes. I would like to fill the boxes with values I am

    >receiving
    >> >> >from
    >> >> >> the comm port. So far so good on that. My problem is that I would
    >> >like
    >> >> >> for the user to be able to click on a text box and then when the

    >value
    >> >> >comes
    >> >> >> across the comm port to have it fill that text box and advance to

    >the
    >> >> next
    >> >> >> box in the array. Conceptually it seems simple enough to me, but

    I
    >> >can't
    >> >> >> get the code to work. I would appreciate any suggestions or code.
    >> >Thanks
    >> >> >> in advance.
    >> >> >> Fred
    >> >> >
    >> >> >
    >> >>
    >> >
    >> >

    >>

    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center