用vb编一个计算器,需要用到数组,看看下面的代码,欢迎来找碴!

这是我的代码,请帮我看看哪有问题:(我是要用数组作个计算器)
 Option Explicit
Dim shu1 As Double, shu2 As Double  '先后输入的两个数
Dim result As Double     '做了运算的结果
Dim process, process0, process1, process2, process3, process4 As Variant '保存数1与各个运算符的过程
Dim judge As Variant    '判断按了那个运算符

Private Sub Command1_Click(Index As Integer)   '0-9数字键
Text1.Text = Text1.Text & Index
Text1.SetFocus
End Sub

Private Sub Command1_KeyPress(Index As Integer, KeyAscii As Integer)    '阻止键盘输入,不过不知为什么没有用
KeyAscii = 0
End Sub

Private Sub Command2_Click(Index As Integer)   ' "."键
Text1.Text = Text1.Text & "."
End Sub

Private Sub Command3_Click()   '退格键
If Text1.Text = "" Then
Exit Sub
End If
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub

Private Sub Command4_Click()    '清除键
Text1.Text = ""
End Sub

Private Sub Command5_Click(Index As Integer)    '做运算,总觉得逻辑上哪有问题
shu1 = Val(Text1.Text)
process = shu1
Text1.Text = ""
 If judge = Command5(0) Then
process0 = shu1 + Command(0)
 ElseIf judge = Command5(1) Then
process1 = shu1 + Command5(1)
 ElseIf judge = Command5(2) Then
process2 = shu1 + Command(2)
ElseIf judge = Command5(3) Then
 process3 = shu1 + Command5(3)
 End If
shu2 = Val(Text1.Text)
End Sub

Private Sub Command6_Click()    '等号
result = process + shu2
Text1.Text = result
If process0 Then
result = shu1 + shu2
ElseIf process1 Then
result = shu1 - shu2
ElseIf process2 Then
result = shu1 * shu2
ElseIf process3 Then
result = shu1 / shu2
End If
End Sub

Private Sub Text1_Change()
If judge = False Then
shu2 = Val(Text1.Text)
End If
Text1.SetFocus
End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值