帮忙看看这两段VB代码有什么问题

[复制链接]
查看11 | 回复2 | 2010-10-2 02:52:54 | 显示全部楼层 |阅读模式
第一段:
Private Sub Command1_Click()
Dim a, b, c As String
a = Text4.Text
b = Text5.Text
c = Text6.Text
If Text7.Text = "+" Then
a = Val(Val(b) + Val(c))
End If
If Text7.Text = "-" Then
a = Val(Val(b) - Val(c))
End If
If Text7.Text = "*" Then
a = Val(Val(b) * Val(c))
End If
If Text7.Text = "/" And c"0" Then
a = Val(Val(b) / Val(c))
End If
If Text7.Text = "/" And c = 0 Then
MsgBox "除数不能为0"
End If
End Sub
第二段:
Private Sub Text7_Change()
If Text7.Text"+" Or "-" Or "*" Or "/" Then MsgBox "请输入正确的运算符"
End Sub
第一段
运行后没有效果
第二段
当text7=7 之类的时候,就提示类型不匹配
该怎样修改,原因是什么

回复

使用道具 举报

千问 | 2010-10-2 02:52:54 | 显示全部楼层
没看出来用Select Case函数吧Select Case Text7.Text '对文本7的内容进行判断Case "+" '如果是+则Text4.text = Val(Text5.Text) + Val(Text6.Text)Case "-" '如果是-则Text4.text = Val(Text5.Text) - Val(Text6.Text)Case "*" '如果是*则Text4.text = Val(Text5.Text) * Val(Text6.Text)Case "/" '如果是/则Text4.text = Val(Text5.Text) / Val(Text6.Text)End Select
回复

使用道具 举报

千问 | 2010-10-2 02:52:54 | 显示全部楼层
把第一段前面的a = Text4.Text,b = Text5.Text,c = Text6.Text反过来写,然后后面作相应的改动,如a = Val(Val(text5.text) + Val(text6.text))
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行