标题: 关于计算出错的问题 [打印本页] 作者: chenwm1973 时间: 2008-3-14 12:59 标题: 关于计算出错的问题 Private Sub CommandButton1_Click() '保存
'先进行数据校对,保证数据准确
'TextBox2=TextBox3+TextBox4
Dim nVbResult As VbMsgBoxResult
Dim nTempD(3) As Double
For i = 0 To 3
nTempD(i) = 0
Next
nTempD(0) = Val(TextBox2.Text)
nTempD(1) = Val(TextBox3.Text)
nTempD(2) = Val(TextBox4.Text)
nTempD(3) = (nTempD(1) + nTempD(2))
If nTempD(0) <> nTempD(3) Then
nVbResult = MsgBox("数据输入有误,是否要保存?" & Chr(13) & "点击‘是’,保存数据;否则不保存。", vbYesNo + vbInformation, "错误信息")
If nVbResult = vbNo Then
TextBox2.SetFocus
TextBox2.SelStart = 0
TextBox2.SelLength = Len(TextBox2.Text)
Exit Sub
End If
End If
end sub
Dim nVbResult As VbMsgBoxResult
Dim nTempD
nTempD = 0
nTempD = Val(TextBox3.Text) + Val(TextBox4.Text)
If TextBox2.Text <> nTempD Then
nVbResult = MsgBox("数据输入有误,是否要保存?" & Chr(13) & "点击‘是’,保存数据;否则不保存。", vbYesNo + vbInformation, "错误信息")
If nVbResult = vbNo Then
TextBox2.SetFocus
TextBox2.SelStart = 0
TextBox2.SelLength = Len(TextBox2.Text)
Exit Sub
End If
End If
End Sub