我在VB6中有一个代码,我需要将其转换为VB.NET,在VB6中,我有5个文本框,分别名为t(0),t(1),t(2),t(3)和t(4)此代码适用于:
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")
现在,在VB.net中,我有一个名为t0,t1,t2,t3,t4
我将如何像在VB6中一样在VB.net中循环浏览这些文本框?
答案 0 :(得分:2)
您可以使用这个概念:
For c As Integer = 0 To 4
CType(Me.Controls("t" & c.ToString()), TextBox).Text = "t" & c.ToString()
Next
在您的情况下,将是这样的:
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