用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 展开
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 展开
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你好,我有现成的代码。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询