How to change the name of multiple textboxes

J

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/ =-
 
C

cfps.Christian

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
 
C

coolCoder

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
 
P

Phill W.

Jan said:
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.
 
C

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top