如何在VB中对textbox控件数组中进行数值计算

2024-12-03 15:34:32
推荐回答(3个)
回答1:

最标准的代码:
Private Sub Text1_GotFocus(Index As Integer)
Dim i, Max As Integer
Dim Sum As Long

Max = Text1.UBound

Sum = 1

For i = 0 To Max
If i <> Max Then
Sum = Sum * Val(IIf(IsNumeric(Text1(i).Text), Text1(i).Text, 1))
Else
Text1(i).Text = Sum
End If
Next i
End Sub

回答2:

调个得到焦点的函数
TEXT2.getpoint()
text2=val(text1)*val(text2)

回答3:

第一种方法:
Private Sub Text1_Click(Index As Integer)
If Index = 2 Then
Text1(2).Text = Val(Text1(0).Text) * Val(Text1(1).Text)
End If
End Sub

第二种方法:
Private Sub Text1_GotFocus(Index As Integer)
If Index = 2 Then
Text1(2).Text = Val(Text1(0).Text) * Val(Text1(1).Text)
End If
End Sub