Reputation: 231
I have a code in VB6 which i need to convert to VB.NET, in VB6 I had 5 textboxes named t(0),t(1),t(2), t(3) and t(4) for which this code worked:
Suma = 0
For i = 1 To 4
Suma = Suma + t(i).Text
Next
If CDbl(Suma) > Label13.Caption Then
t(Index).Text = 0
Suma = 0
t(Index).SelStart = 0
t(Index).SelLength = 1
For i = 1 To 4
Suma = Suma + t(i).Text
Next
End If
t(0).Text = Format(Label13.Caption - CDbl(Suma), "#,##0.00")
Else
Suma = 0
For i = 0 To 3
Suma = Suma + t(i).Text
Next
If CDbl(Suma) > Label13.Caption Then
t(Index).Text = 0
Suma = 0
t(Index).SelStart = 0
t(Index).SelLength = 1
For i = 0 To 3
Suma = Suma + t(i).Text
Next
End If
t(4).Text = Format(Label13.Caption - CDbl(Suma), "#,##0.00")
Now, in VB.net i have textboxes named: t0,t1,t2,t3,t4
How would i loop through these textboxes in VB.net like i did in VB6?
Upvotes: 1
Views: 206
Reputation: 5453
You can use this concept :
For c As Integer = 0 To 4
CType(Me.Controls("t" & c.ToString()), TextBox).Text = "t" & c.ToString()
Next
In your case, it would be something like this :
Suma = 0
For i = 1 To 4
Suma = Suma + CInt(CType(Me.Controls("t" & i.ToString()), TextBox).Text)
Next
'Rest of your code following the above concept
Upvotes: 2