| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 664 人关注过本帖
标题:[求助]关于计算器的运算符问题,
只看楼主 加入收藏
sishui198
Rank: 1
等 级:新手上路
帖 子:113
专家分:0
注 册:2007-4-12
收藏
 问题点数:0 回复次数:6 
[求助]关于计算器的运算符问题,
  1. Dim v As Boolean '是否第一次按运算符
    Dim x, y As Double '存放两次数
    Private Sub Cmdcompute_Click(Index As Integer)
    If v Then '第一次运算符
    x = Val(Txtoutput.Text) '保存
    v = False
    Else
    y = Val(Txtoutput.Text)
    Select Case Index
    Case 0
    Txtoutput.Text = x + y
  2. Case 1
    Txtoutput.Text = x - y
  3. Case 2
    Txtoutput.Text = x * y
  4. Case 3
    If y <> 0 Then
    Txtoutput.Text = x / y
    Else
    MsgBox ("Error") '如果除数为0,报错
    Txtoutput.Text = x
    v = False
    End If
    Case4
    y = 0
    v = False
    End Select
    x = Val(Txtoutput.Text)
    End If

End Sub

Private Sub CmdNegative_Click()
Txtoutput.Text = Trim(Str(-Val(Txtoutput.Text)))
End Sub

Private Sub CmdNumber_Click(Index As Integer)
If Index = 10 Then
Txtoutput.Text = "0."
Else
Txtoutput.Text = CmdNumber(Index).Caption

End If

End Sub

Private Sub Command1_Click()

End Sub


Private Sub Command2_Click()
Txtoutput.Text = ""
v = False

End Sub


Private Sub end_Click()
Unload Me
End Sub

为什么 我在点 Cmdcompute时,出错,麻烦说详细一点,谢谢。

搜索更多相关主题的帖子: 运算符 计算器 Txtoutput Text Case 
2007-04-30 15:49
Kendy123456
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:62
帖 子:2720
专家分:0
注 册:2007-1-3
收藏
得分:0 

1.错误信息都不贴出来 楼主太懒了吧
难道要帮你一句一句调试?

2. 代码里面哪里有cmdCompute??????

求助都这么不细心 写代码更容易犯错误


2007-04-30 15:59
huangwy
Rank: 1
等 级:新手上路
威 望:2
帖 子:297
专家分:0
注 册:2007-3-23
收藏
得分:0 

你在按数字键的时候,就应该对数据V进行置位
而不是在一个无关的按钮中来做这件事
第二个,你下面这个语句不对
Txtoutput.Text = CmdNumber(Index).Caption
应该是Txtoutput.Text =Txtoutput.Text + CmdNumber(Index).Caption吧

2007-04-30 16:05
huangwy
Rank: 1
等 级:新手上路
威 望:2
帖 子:297
专家分:0
注 册:2007-3-23
收藏
得分:0 
并且我觉得也没必要用cmdNumber(index).Caption这么麻烦
直接用Txtoutput.Text =Txtoutput.Text & cstr(index)不是更一目了然吗
2007-04-30 16:08
sishui198
Rank: 1
等 级:新手上路
帖 子:113
专家分:0
注 册:2007-4-12
收藏
得分:0 

Private Sub Cmdcompute_Click(Index As Integer)
If v Then '第一次运算符
x = Val(Txtoutput.Text) '保存
v = False
Else
y = Val(Txtoutput.Text)
Select Case Index
Case 0
Txtoutput.Text = x + y
Case 1
Txtoutput.Text = x - y
Case 2
Txtoutput.Text = x * y
Case 3
If y <> 0 Then
Txtoutput.Text = x / y
Else
MsgBox ("Error") '如果除数为0,报错
Txtoutput.Text = x
v = False
End If
Case4
y = 0
v = False
End Select
x = Val(Txtoutput.Text)
End If
End Sub

在这里出现问题?


2007-04-30 16:15
Kendy123456
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:62
帖 子:2720
专家分:0
注 册:2007-1-3
收藏
得分:0 

出什么错? 错误信息是什么?

粗看一下没发现有什么问题
要不你吧 Txtoutput.Text = x + y 改成 cstr(x + y)

另外 你这个程序只能输入一位数运算吧 二位数看代码是输不进了


2007-04-30 16:25
sishui198
Rank: 1
等 级:新手上路
帖 子:113
专家分:0
注 册:2007-4-12
收藏
得分:0 

是呀


2007-04-30 17:32
快速回复:[求助]关于计算器的运算符问题,
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019678 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved