how to join up a string and a integer to be a object name ?

  • Thread starter Thread starter THY
  • Start date Start date
T

THY

Hi,

Assuming that I have 5 textboxes, they are textbox1, textbox2, textbox3,
textbox4, textbox5.
and now I am on a for loop as below. but how can I make it join the word
"textbox" and my i value together and be a textbox object ?

it should be something like that, but I dont know the real coding.

for i = 1 to 5
("textbox" & i).text = "hello"
next


anyone know it ?

your help is real appreaciated. Thanks.
 
THY said:
Hi,

Assuming that I have 5 textboxes, they are textbox1, textbox2,
textbox3, textbox4, textbox5.
and now I am on a for loop as below. but how can I make it join the
word "textbox" and my i value together and be a textbox object ?

it should be something like that, but I dont know the real coding.

for i = 1 to 5
("textbox" & i).text = "hello"
next

CType(FindControl("textbox" & i),TextBox).Text="Hello"
 
THY said:
Hi,

Assuming that I have 5 textboxes, they are textbox1, textbox2, textbox3,
textbox4, textbox5.
and now I am on a for loop as below. but how can I make it join the word
"textbox" and my i value together and be a textbox object ?

it should be something like that, but I dont know the real coding.

for i = 1 to 5
("textbox" & i).text = "hello"
next

Private textBoxArray As TextBox() = New TextBox() {textbox1, textbox2, ...
textbox5}

For i = 1 To 5
textBoxArray(i).Text = "hello"
Next
 
This is a good way too, thanks John !

John Saunders said:
Private textBoxArray As TextBox() = New TextBox() {textbox1, textbox2, ...
textbox5}

For i = 1 To 5
textBoxArray(i).Text = "hello"
Next
 
Back
Top