vb计算代码

来源:百度知道 编辑:UC知道 时间:2024/05/30 17:50:11
用text1 label1(+、-、*、/) text2 label2(=) text3(结果)
按键有command1(.)command2(c) command3(off)command4(+ - * /)command5(=)
用最简单的代码。
请写完全,不要漏写。

我写的完全点---------------
首先要确定text1 和text2 都只能输入数字,
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii = 8 Or KeyAscii = 46 Then
If Text1.Text = "0" Then
Text1.Text = ""
End If
Else
KeyAscii = 0
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii = 8 Or KeyAscii = 46 Then
If Text2.Text = "0" Then
Text2.Text = ""
End If
Else
KeyAscii = 0
End If
End Sub

思想是整除的分母必须不是零。
Private Sub Command2_Click()
If c = 1 Then
Text3.Text = Text1.Text + Text2.Text
ElseIf c = 2 Then
Text3.Text = Text1.Text - Text2.Text
ElseIf c = 3 Then
Text3.Text = Text1.Text * Text2.Text
ElseIf c = 4 Then
If Text2.Text = 0 Then
Text2.Text = "整除为零"
Else
Text3.Text = Text1.Text / Text2.Text