帮忙分析下这个VB程序 谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/28 19:26:56
写了个简单的计算器程序 可是在Case 11到Case 15之间老是出现“类型不匹配”问题 自己也没学多久 看了好久也不知道错在哪里

下面是代码

Dim num1, num2 As Double
Dim sum As Double
Dim act As Integer
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
If Text1.Text = "" Then
Text1.Text = "0"
Else
Text1.Text = Text1.Text + "0"
End If
Case 1
If Text1.Text = "" Then
Text1.Text = "1"
Else
Text1.Text = Text1.Text + "1"
End If
Case 2
If Text1.Text = "" Then
Text1.Text = "2"
Else
Text1.Text = Text1.Text + "2"
End If
Case 3
If Text1.Text = "" Then
Text1.Text = "3"
Else
Text1.Text = Text1.Text + "3"
End If
Case 4
If Text1.Text = "" Then
Text1.Text = "4"<

你写的代码体积太大了哦.你这是不是在0-9之间的数字键区分别向Text中添置用户选择的呢?还有也实现了运算类型的选择??出错的原因可能是因为你的函数使用错误了,你试试看用CDEC()试看看吧.还有你的类型NUM1,2应该是为Single才好!!你用了Index可以把它写成Text1.text=Text1.text+Command1(Index).Caption这样的语句啊,可以省很多事的.还有要编出个真正可以用的还真不简单,要考虑的有很多方面的问题!我有编过一个,和系统的差不多.你要我给你发吧,留个QQ邮箱给我吧...我QQ546884609 互相学习啊!!

Case 11
If Text1.Text = "" Then
Text1.Text = "+"
End If
num1 = CDbl(Text1.Text)
Text1.Text = ""
act = 1

这是Case11的代码,
如果Text1为空的时候,你让它先为+了, 然后
CDbl("+")
当然会出错..