Private Sub Command1_Click() If Trim(Text1) = "" Or Trim(Text2) = "" Or Trim(Text3) = "" Then Exit Sub ElseIf Not IsNumeric(Text1) And _ Not IsNumeric(Text2) And Not IsNumeric(Text3) Then MsgBox "必需是数字" Exit Sub Else Text4 = Val(Text1) + Val(Text2) + Val(Text3) End If End Sub
Private Sub Text4_GotFocus() If Trim(Text1) = "" Or Trim(Text2) = "" Or Trim(Text3) = "" Then Exit Sub ElseIf Not IsNumeric(Text1) And _ Not IsNumeric(Text2) And Not IsNumeric(Text3) Then MsgBox "必需是数字" Exit Sub Else Text4 = Val(Text1) + Val(Text2) + Val(Text3) End IfEnd Sub
Private Sub Text1_Change() If Not IsNumeric(Text1.Text) Then Text1.Text = "" Exit Sub End If AutoAdd End SubPrivate Sub Text2_Change() If Not IsNumeric(Text2.Text) Then Text2.Text = "" Exit Sub End If AutoAdd End SubPrivate Sub Text3_Change() If Not IsNumeric(Text3.Text) Then Text3.Text = "" Exit Sub End If AutoAdd End Sub Private Sub AutoAdd() Dim intNum1, intNum2, intNum3 As Integer
在command_click事件中写代码:
TEXT4=TEXT1+TEXT2+TEXT3
If Trim(Text1) = "" Or Trim(Text2) = "" Or Trim(Text3) = "" Then
Exit Sub
ElseIf Not IsNumeric(Text1) And _
Not IsNumeric(Text2) And Not IsNumeric(Text3) Then
MsgBox "必需是数字"
Exit Sub
Else
Text4 = Val(Text1) + Val(Text2) + Val(Text3)
End If
End Sub
If Trim(Text1) = "" Or Trim(Text2) = "" Or Trim(Text3) = "" Then
Exit Sub
ElseIf Not IsNumeric(Text1) And _
Not IsNumeric(Text2) And Not IsNumeric(Text3) Then
MsgBox "必需是数字"
Exit Sub
Else
Text4 = Val(Text1) + Val(Text2) + Val(Text3)
End IfEnd Sub
If Not IsNumeric(Text1.Text) Then
Text1.Text = ""
Exit Sub
End If
AutoAdd
End SubPrivate Sub Text2_Change()
If Not IsNumeric(Text2.Text) Then
Text2.Text = ""
Exit Sub
End If
AutoAdd
End SubPrivate Sub Text3_Change()
If Not IsNumeric(Text3.Text) Then
Text3.Text = ""
Exit Sub
End If
AutoAdd
End Sub
Private Sub AutoAdd()
Dim intNum1, intNum2, intNum3 As Integer
intNum1 = CInt(IIf(IsNumeric(Text1.Text), Text1.Text, 0))
intNum2 = CInt(IIf(IsNumeric(Text2.Text), Text2.Text, 0))
intNum3 = CInt(IIf(IsNumeric(Text3.Text), Text3.Text, 0))
Text4.Text = ""
Text4.Text = intNum1 + intNum2 + intNum3
End Sub