change text property to various textbox

S

Sergio

how do i change the text property to a lot of textbox if all textbox are
calle textbox1, textbox2 .... instead of doing it one bye one, i mean
something like

for i as integer = 0 to 10

textbox & i .text = i

next i
 
J

Jack Jackson

how do i change the text property to a lot of textbox if all textbox are
calle textbox1, textbox2 .... instead of doing it one bye one, i mean
something like

for i as integer = 0 to 10

textbox & i .text = i

next i

If they are all children of a form or some other container:

For Each ctl As Control In Me.Controls
If ctl Is Textbox Then ' This will do all textboxes
ctl.Text = "something"
End If
Next
 
P

Phill W.

Sergio said:
how do i change the text property to a lot of textbox if all textbox are
calle textbox1, textbox2 .... instead of doing it one bye one, i mean
something like

for i as integer = 0 to 10
textbox & i .text = i
next i

You don't.
Finding Controls by name is a pain in .Net. Far better to use the
facilities of the [new] language.

Use a list of TextBoxes, load each of your individual TextBoxes (each
with its own, /meaningful/ name) into it, then loop through the list, as
in:

Private tbList As New ArrayList
' VB'2005 and later can use "List(Of TextBox)"

Sub New()
InitializeControls()

tbList.Add( textbox1 )
tbList.Add( textbox2 )
. . .
End Sub

Sub Button1_Click( ... ) Handles Button1.Click
For Each tb as TextBox in tbList
tb.Text = ""
Next
' or, from your example
For iSub as Integer = 0 To tbList.Count - 1
tbList( iSub ).Text = iSub.ToString()
Next
End Sub

HTH,
Phill W.
 

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