用vb做一个小型计算器,一个文本框,0-9,加减乘除,清除,等于几个按钮,输出结果是混乱的,请高手指点下

下面是代码,请帮忙看看哪儿出问题了Dimnum1AsDoubleDimnum2AsDoubleDimnum3AsDoubleDimnum4AsDoublePrivateS... 下面是代码,请帮忙看看哪儿出问题了
Dim num1 As Double
Dim num2 As Double
Dim num3 As Double
Dim num4 As Double
Private Sub Command1_Click()
num1 = Text1
Text1 = ""
End Sub
Private Sub Command10_Click()
Text1 = Text1 & 5
End Sub
Private Sub Command11_Click()
Text1 = Text1 & 6
End Sub
Private Sub Command12_Click()
Text1 = Text1 & 7
End Sub
Private Sub Command13_Click()
Text1 = Text1 & 8
End Sub
Private Sub Command14_Click()
Text1 = Text1 & 9
End Sub
Private Sub Command15_Click()
Text1 = Text1 & 0
End Sub
Private Sub Command16_Click()
If num = 1 Then
Text1 = num1 + Val(Text1)
ElseIf num = 2 Then
Text1 = num2 - Val(Text1)
ElseIf num = 3 Then
Text1 = num3 * Val(Text1)
Else
Text1 = num4 / Val(Text1)
End If
End Sub

Private Sub Command2_Click()
num2 = Text1
Text1 = ""
End Sub
Private Sub Command3_Click()
num3 = Text1
Text1 = ""
End Sub
Private Sub Command4_Click()
num4 = Text1
Text1 = ""
End Sub
Private Sub Command5_Click()
Text1 = ""
End Sub
Private Sub Command6_Click()
Text1 = Text1 & 1
End Sub
Private Sub Command7_Click()
Text1 = Text1 & 2
End Sub
Private Sub Command8_Click()
Text1 = Text1 & 3
End Sub
Private Sub Command9_Click()
Text1 = Text1 & 4
End Sub
展开
 我来答
百度网友8343d20
2012-09-19 · TA获得超过785个赞
知道小有建树答主
回答量:480
采纳率:100%
帮助的人:243万
展开全部
Private Sub Command16_Click()
If num = 1 Then
——————
所有的num没有赋值
类似修改如下:
Private Sub Command2_Click()
num2 = Text1
num=2
Text1 = ""
End Sub
更多追问追答
追问
我试了,不行,只有按除法时有用,其它的都不行,能在帮忙看看吗?
追答
num全部赋值了吗一共四个,声明了没有
ysy_dyh
2012-09-19 · TA获得超过153个赞
知道小有建树答主
回答量:260
采纳率:0%
帮助的人:145万
展开全部
Option Compare DatabaseOption Explicit
Dim num1 As LongDim yunsuan As Integer
Private Sub Command4_Click()
Me.Text2 = Me.Text2 + "1"
End Sub

Private Sub Command5_Click()
Me.Text2 = Me.Text2 + "2"
End Sub

Private Sub Command6_Click()
Me.Text2 = Me.Text2 + "3"
End Sub
Private Sub Command7_Click()
Me.Text2 = Me.Text2 + "4"
End Sub

Private Sub Command8_Click()
Me.Text2 = Me.Text2 + "5"
End Sub

Private Sub Command9_Click()
Me.Text2 = Me.Text2 + "6"
End Sub
Private Sub Command10_Click()
Me.Text2 = Me.Text2 + "7"
End Sub

Private Sub Command11_Click()
Me.Text2 = Me.Text2 + "8"
End Sub

Private Sub Command12_Click()
Me.Text2 = Me.Text2 + "9"
End Sub
Private Sub Command13_Click()
Me.Text2 = Me.Text2 + "0"
End Sub
Private Sub Command14_Click()
Me.Text2 = ""
num1 = 0
End Sub

Private Sub Command15_Click()
Dim num2 As Long
num2 = Val(Me.Text2)
Select Case yunsuan
Case 1
num1 = num1 + num2
Case 2
num1 = num1 - num2
Case 3
num1 = num1 * num2
Case 4
If num2 = 0 Then
Me.Text2 = "除零啦"
Exit Sub
Else
num1 = num1 / num2
End If
End Select
Me.Text2 = CStr(num1)
End Sub
Private Sub Command16_Click()
num1 = Val(Me.Text2)
Me.Text2 = ""
yunsuan = 1
Me.Label20.Caption = "+"
End Sub
Private Sub Command17_Click()
num1 = Val(Me.Text2)
Me.Text2 = ""
yunsuan = 2
Me.Label20.Caption = "-"
End Sub
Private Sub Command18_Click()
num1 = Val(Me.Text2)
Me.Text2 = ""
yunsuan = 3
Me.Label20.Caption = "-"
End Sub
Private Sub Command19_Click()
num1 = Val(Me.Text2)
Me.Text2 = ""
yunsuan = 4
Me.Label20.Caption = "/"
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.Text2 = ""
num1 = 0
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
天涯客家学子
2012-09-19 · TA获得超过242个赞
知道小有建树答主
回答量:392
采纳率:100%
帮助的人:185万
展开全部
你好,我有现成的代码。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式