erik erik - 5 months ago 31
Vb.net Question

put array to textboxes, array is smaller than number of textboxes

all, been busy for dates now to sort it out, no succes. please help! i got one array of 8 textboxes and one of 2:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim arrA() As TextBox = {a1, a2} 'names of people
Dim arrB() As TextBox = {b1, b2, b3, b4,b5,b6,b7,b8 } 'output textboxes


now i want my 8 output textboxes ((arrb()) filled with the names of people (arraA()) in a LOOP after the buttonclick. so, in this case all names will be visible 4 times .Ive tried several options, nothing worked so i did not post (all) my tries... thx you all!!!

so textboxes (arrB) on form will look like this:
name1
name2
name1
name2
name1
name2
name1
name2

Uno Uno
Answer

You can easily solve it with the Mod operator:

Dim index = 0

For Each output In arrB
    output.Text = arrA(index Mod arrA.Count).Text
    index++
Next

Or

For index = 0 To arrB.Count - 1
    arrB(index).Text = arrA(index Mod arrA.Count).Text
Next