Home All Groups Group Topic Archive Search About

How to change the name of multiple textboxes

Author
21 Nov 2007 5:21 PM
Jan
Hi there,

I have a lot of textboxes in a form, i numberd them from from 1 til 10.

for example:  txtZpr1.text
                      txtZpr2.text  etc..

I want to fill these textboxes by using a  loop.

Is there a way to fill them by changing the number of the textbox??

TIA Jan




--------------=  Posted using GrabIt  =----------------
------=  Binary Usenet downloading made easy =---------
-=  Get GrabIt for free from http://www.shemes.com/  =-

Author
21 Nov 2007 6:48 PM
cfps.Christian
On Nov 21, 11:21 am, "Jan" <> wrote:
> Hi there,
>
> I have a lot of textboxes in a form, i numberd them from from 1 til 10.
>
> for example:  txtZpr1.text
>                       txtZpr2.text  etc..
>
> I want to fill these textboxes by using a  loop.
>
> Is there a way to fill them by changing the number of the textbox??
>
> TIA Jan
>

for I as integer = 0 to 10
     dim txt as TextBox = CType(Me.Controls("txtZpr" & I.ToString()),
TextBox)
     txt.Text = "New Text"
Next
Author
22 Nov 2007 5:56 AM
coolCoder
Show quote Hide quote
On Nov 21, 10:21 pm, "Jan" <baggerd***@hotmail.com> wrote:
> Hi there,
>
> I have a lot of textboxes in a form, i numberd them from from 1 til 10.
>
> for example:  txtZpr1.text
>                       txtZpr2.text  etc..
>
> I want to fill these textboxes by using a  loop.
>
> Is there a way to fill them by changing the number of the textbox??
>
> TIA Jan
>
> --------------=  Posted using GrabIt  =----------------
> ------=  Binary Usenet downloading made easy =---------
> -=  Get GrabIt for free fromhttp://www.shemes.com/ =-

You can use reflection to get all the controls of the form, of your
interest, and then set any property / invoke any member on those
controls. Google this for the syntax, which is easy enough to be
understood.

Thanks,
coolCoder

--------------------------------------------------------------------------------------------------------------------------------------------------
If you find this post helpful, please rate it.
Author
22 Nov 2007 12:24 PM
Phill W.
Jan wrote:

> I have a lot of textboxes in a form, i numberd them from from 1 til 10.
> for example:  txtZpr1.text, txtZpr2.text  etc..
>
> I want to fill these textboxes by using a  loop.
>
> Is there a way to fill them by changing the number of the textbox??

Yes, there is.

But don't.

Visual Basic may not have VB's Control Arrays but, instead, you can have
Arrays of Controls:

Dim allmyTextBoxes As TextBox() _
    = {txtZpr1, txtZpr2, ... txtZpr10}

For Each tb as TextBox in allmyTextBoxes
    tb.Text = tb.Name
Next

HTH,
    Phill  W.
Author
22 Nov 2007 5:55 PM
Cor Ligthert[MVP]
exact,

Just to show that it is as well my favorite which I learned from an answer
from Armin by the way,

:-)

Cor