VB程序 计算问题

来源:百度知道 编辑:UC知道 时间:2024/06/17 13:50:04
Private Sub Text1_Change()
Dim a As String
a = Val(Text1.Text)

End Sub

Private Sub Text2_Change()
Dim b As String
b = Val(Text2.Text)

End Sub

Private Sub Text3_Change()
Dim c As Double
c = Val(Text3.Text)
Text3.Text = Val(Text1.Text) * Val(Text2.Text)

End Sub

我要实现面积计算:当text1中输入长度(3),text2中输入宽度(5)后。text3中马上自动现实初面积值(15)。更换宽度和长度后,text3中自动清除前次计算结果 而现实本次计算结果。

单是我的程序实现不了text3中的值自动显示。我是初学者,请大虾们指点!

Private Sub Text1_Change()
If IsNumeric(Text1.Text) And IsNumeric(Text2.Text) Then
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
Else
Text3.Text = ""
End If
End Sub

Private Sub Text2_Change()
If IsNumeric(Text1.Text) And IsNumeric(Text2.Text) Then
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
Else
Text3.Text = ""
End If
End Sub

Private Sub Text1_Change()
Text3_Change
End Sub

Private Sub Text2_Change()
Text3_Change
End Sub

Private Sub Text3_Change()

Dim c As Double
On Error GoTo er
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
Exit Sub
er:
Text3.Text = "Err"
End Sub

最后加一个清屏函数
text.cls