VB中,在text2中输入后按回车没反应,只有“咚”?

来源:百度知道 编辑:UC知道 时间:2024/07/04 02:21:57
(题目:简单加法,例如1+2=3)

Private Sub Text1_LostFocus()
If Not IsNumeric(Text1) Then
Text1 = ""
Text1.SetFocus
End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Not IsNumeric(Text2) Then
Text2 = ""
End If
End If
End Sub

Private Sub Text3_GotFocus()
Text3 = Val(Text1) + Val(Text2)
End Sub

正确代码:
Private Sub Text1_LostFocus()
If Not IsNumeric(Text1) Then
Text1 = ""
Text1.SetFocus
End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Not IsNumeric(Text2) Then
Text2 = ""
End If
End If
End Sub

Private Sub Text3_GotFocus()
Text3 = Val(Text1) + Val(Text2)
End Sub