计算器代码出错,谁来帮下忙?
vb吧
全部回复
仅看楼主
level 6
Private Sub Command1_Click()
Dim a
#, b#
, c
#, d#

a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If Not IsNumeric(Text1) ThenMsgBox "输入有误"
ElseIf Not IsNumeric(Text2) Then
MsgBox "输入有误"
ElseSelect Case c
Case "+"
d = a + b
Case "-"
d = a - b
Case "*"
d = a * b
Case "/"
if len(text3.text)〈〉0 Then
d = a / b
Text4.Text = d
ElseIf Len(Text3.Text) = 0 Then
MsgBox "除数不能为零
"End If
End Select
End Sub
Private Sub Command2_Click()
End
end sub
2013年04月24日 16点04分 1
level 9
好像是类型不匹配 select case那里似乎也有问题
2013年04月24日 16点04分 2
该怎么弄?
2013年04月24日 16点04分
回复 米诺双城 :我不知道,因为你的代码我有些看不懂,我也不能帮你了,帮你顶下[呵呵]
2013年04月24日 16点04分
回复 米诺双城 :变量c直接定义成字符串类型的吧
2013年04月24日 16点04分
回复 被她伤过的我 :你能帮我把代码改一下么?
2013年04月24日 16点04分
level 9
Private Sub Command1_Click()
Dim a As Double, b As Double, c As String, d As Double
a = Val(Text1.Text): b = Val(Text3.Text): c = Text2.Text
Select Case c
Case "+"
d = a + b
Text4.Text = d
Case "-"
d = a - b
Text4.Text = d
Case "*"
d = a * b
Text4.Text = d
Case "/"
If b = 0 Then
MsgBox "除数不能为零。", vbOKOnly, "提示"
Exit Sub
Else
d = a / b
Text4.Text = d
End If
End Select
End Sub
如果你急用的话 你就试下吧 很多东西我也不会
2013年04月24日 17点04分 3
level 9
界面是这个样子的
2013年04月24日 17点04分 4
level 13
c 应该定义为 String类型
你的<> 是在中文输入模式下输入的
2013年04月25日 00点04分 6
谢啦
2013年04月26日 03点04分
level 11
Private Sub Command1_Click()
If IsNumeric(Text1) = False Or IsNumeric(Text2) = False Then
MsgBox "输入有误"
Else
If Text3 <> "+" And Text3 <> "-" And Text3 <> "*" And Text3 <> "/" Then
MsgBox "请输入运算符号"
ElseIf Text3 = "+" Then
Text4 = Val(Text1) + Val(Text2)
ElseIf Text3 = "-" Then
Text4 = Text1 - Text2
ElseIf Text3 = "*" Then
Text4 = Text1 * Text2
ElseIf Text2 <> 0 And Text3 = "/" Then
Text4 = Text1 / Text2
Else
MsgBox "除数不能为零"
End If
End If
End Sub
2013年04月25日 04点04分 7
谢啦
2013年04月25日 04点04分
1