谁能写个VB代码是 计算机的加减乘除的
答案:4 悬赏:80 手机版
解决时间 2021-03-22 14:31
- 提问者网友:欲劫无渡
- 2021-03-21 18:59
谁能写个VB代码是 计算机的加减乘除的
最佳答案
- 五星知识达人网友:渡鹤影
- 2021-03-21 19:22
这个没有用按钮
用输入计算 你可以设置成 button 就可以
Private Sub Command1_Click() '清零
Text3.Text = ""
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
Private Sub Command3_Click() '计算器加计算
If Val(Text1.Text) > 0 Then
Text3.Text = Val(Text1.Text) + Val(Text3.Text)
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "+" & Val(Text1.Text)
Text1.Text = ""
Text1.SetFocus
End If
End Sub
Private Sub Command4_Click() '计算器减计算
If Val(Text1.Text) > 0 Then
Text3.Text = -Val(Text1.Text) + Val(Text3.Text)
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "-" & Val(Text1.Text)
Text1.Text = ""
Text1.SetFocus
End If
End Sub
Private Sub Command5_Click()
If Val(Text1.Text) > 0 Then
If Text3.Text = "" Then
Text3.Text = Text1.Text
Else
Text3.Text = Val(Text1.Text) * Val(Text3.Text)
End If
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "×" & Val(Text1.Text)
Text1.Text = ""
Text1.SetFocus
End If
End Sub
Private Sub Command6_Click()
If Val(Text1.Text) > 0 Then
If Text3.Text = "" Then
Text3.Text = Text1.Text
Else
Text3.Text = Val(Text3.Text) / Val(Text1.Text)
End If
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "÷" & Val(Text1.Text)
Text1.Text = ""
Text1.SetFocus
End If
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) '计算器计算
If Val(Text1.Text) > 0 Then '输入数据有效
If Text2.Text = "" Then
If KeyCode = vbKeyReturn Then '计算器加计算
Text3.Text = Val(Text1.Text) + Val(Text3.Text)
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text1.Text
Text1.Text = ""
End If
If KeyCode = vbKeySpace Then '计算器减计算
Text3.Text = -Val(Text1.Text) + Val(Text3.Text)
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "-" & Val(Text1.Text)
Text1.Text = ""
End If
Else
If KeyCode = vbKeyReturn Then '计算器加计算
Text3.Text = Val(Text1.Text) + Val(Text3.Text)
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "+" & Val(Text1.Text)
Text1.Text = ""
End If
If KeyCode = vbKeySpace Then '计算器减计算
Text3.Text = -Val(Text1.Text) + Val(Text3.Text)
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "-" & Val(Text1.Text)
Text1.Text = ""
End If
End If
End If
Text1.SetFocus
End Sub
Private Sub Command2_Click()
End
End Sub
仅供参考
用输入计算 你可以设置成 button 就可以
Private Sub Command1_Click() '清零
Text3.Text = ""
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
Private Sub Command3_Click() '计算器加计算
If Val(Text1.Text) > 0 Then
Text3.Text = Val(Text1.Text) + Val(Text3.Text)
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "+" & Val(Text1.Text)
Text1.Text = ""
Text1.SetFocus
End If
End Sub
Private Sub Command4_Click() '计算器减计算
If Val(Text1.Text) > 0 Then
Text3.Text = -Val(Text1.Text) + Val(Text3.Text)
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "-" & Val(Text1.Text)
Text1.Text = ""
Text1.SetFocus
End If
End Sub
Private Sub Command5_Click()
If Val(Text1.Text) > 0 Then
If Text3.Text = "" Then
Text3.Text = Text1.Text
Else
Text3.Text = Val(Text1.Text) * Val(Text3.Text)
End If
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "×" & Val(Text1.Text)
Text1.Text = ""
Text1.SetFocus
End If
End Sub
Private Sub Command6_Click()
If Val(Text1.Text) > 0 Then
If Text3.Text = "" Then
Text3.Text = Text1.Text
Else
Text3.Text = Val(Text3.Text) / Val(Text1.Text)
End If
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "÷" & Val(Text1.Text)
Text1.Text = ""
Text1.SetFocus
End If
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) '计算器计算
If Val(Text1.Text) > 0 Then '输入数据有效
If Text2.Text = "" Then
If KeyCode = vbKeyReturn Then '计算器加计算
Text3.Text = Val(Text1.Text) + Val(Text3.Text)
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text1.Text
Text1.Text = ""
End If
If KeyCode = vbKeySpace Then '计算器减计算
Text3.Text = -Val(Text1.Text) + Val(Text3.Text)
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "-" & Val(Text1.Text)
Text1.Text = ""
End If
Else
If KeyCode = vbKeyReturn Then '计算器加计算
Text3.Text = Val(Text1.Text) + Val(Text3.Text)
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "+" & Val(Text1.Text)
Text1.Text = ""
End If
If KeyCode = vbKeySpace Then '计算器减计算
Text3.Text = -Val(Text1.Text) + Val(Text3.Text)
Text3.Text = Format(Text3.Text, "0.00")
Text2.Text = Text2.Text & "-" & Val(Text1.Text)
Text1.Text = ""
End If
End If
End If
Text1.SetFocus
End Sub
Private Sub Command2_Click()
End
End Sub
仅供参考
全部回答
- 1楼网友:爱难随人意
- 2021-03-21 20:52
Sub test()
Dim a As Integer
a = (12 + 2 * 3) / 6 - 2
MsgBox a
End Sub
- 2楼网友:舊物识亽
- 2021-03-21 20:21
vc我会
- 3楼网友:大漠
- 2021-03-21 19:32
新建 text1.text
text1.text = Val(Text1.Text) + "2" '就是 text1.text 中的数值 加 2
text1.text = Val(Text1.Text) - "2" '就是 text1.text 中的数值 减 2
text1.text = Val(Text1.Text) * "2" '就是 text1.text 中的数值 乘 2
text1.text = Val(Text1.Text) / "2" '就是 text1.text 中的数值 除 2
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯