0

This is my code

  Dim str As String = "str1,str2"
    Dim array() As String = str.Split(",")
    Dim MyListOfTextBoxes() As TextBox = {TextBox1, TextBox2, TextBox3}
    For index = 0 To array.Count - 1
        For i = 0 To MyListOfTextBoxes.Length - 1
            MyListOfTextBoxes(i).Text = array(index)
        Next
    Next

I have 5 textboxes. I want to fill just textbox1 and textbox2 with array value. because no I have to word. but when I run the code "str1" repetition on textbox1,textbox2 and textbox3.

1
  • You really shouldn't hardcode in your TextBox names. What happens when the form changes? And you add/delete a TextBox? Commented Jun 24, 2012 at 22:14

2 Answers 2

1

you need one loop to do it

  Dim str As String = "str1,str2"
    Dim array() As String = str.Split(",")
    Dim MyListOfTextBoxes() As TextBox = {TextBox1, TextBox2, TextBox3}
    For index = 0 To array.Count - 1
       if(MyListOfTextBoxes.Length>index)
       MyListOfTextBoxes(index).Text = array(index)
    Next
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your response.MyListOfTextBoxes(index) is correct.
0

That's because your code runs through elements 0, 1 and 2, which correspond to TextBox1, TextBox2, and TextBox3. If you only want to populate TextBox1 and TextBox2 then remove TextBox3 from the array.

You also have a loop within another loop - I don't see why you're doing that.

1 Comment

but i need textbox3 because my str maybe have 3 word and textbox mustbe fill.with For index = 0 To array.Count - 1 i put the array value in textboxes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.