For a start, .NET arrays are zero-based. In VB.NET you create an array by specifying the upper bound. If you want an array with 18 elements then the upper bound is 17. Those elements then occupy indexes 0 to 17, not 1 to 18.
You could do this:but I personally would not.
For i As Integer = 0 To 17 Step 1
Me.par(i) = CInt(Me.Controls(String.Format("tbH{0}P", i + 1)).Text)
Me.score(i) = CInt(Me.Controls(String.Format("tbH{0}S", i + 1)).Text)
Next i
If you want to loop through controls then I strongly suggest that you create an array:
Private parFields As TextBox()
Private scoreFields As TextBox()
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As EventArgs) Handles MyBase.Load
Me.parFields = New TextBox() {tbH1P, _
tbH2P, _
tbH3P, _
tbH4P, _
tbH5P, _
tbH6P, _
tbH7P, _
tbH8P, _
tbH9P, _
tbH10P, _
tbH11P, _
tbH12P, _
tbH13P, _
tbH14P, _
tbH15P, _
tbH16P, _
tbH17P, _
tbH18P}
Me.scoreFields = New TextBox() {tbH1S, _
tbH2S, _
tbH3S, _
tbH4S, _
tbH5S, _
tbH6S, _
tbH7S, _
tbH8S, _
tbH9S, _
tbH10S, _
tbH11S, _
tbH12S, _
tbH13S, _
tbH14S, _
tbH15S, _
tbH16S, _
tbH17S, _
tbH18S}
End Sub
So it's a little bit of code. We write code for a living.
Enter your message below
Sign in or Join us (it's free).