| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 470 人关注过本帖
标题:请哪位老师解答!关于计算的程序
只看楼主 加入收藏
dream725
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-5-21
收藏
 问题点数:0 回复次数:1 
请哪位老师解答!关于计算的程序
请教:一个简单的股票利润计算程序,为何会计算不出正确的结果?

Private m1, m2, c1, c2, x2, s1 As Single

Private Sub Command2_Click()
m1 = 0: m2 = 0: c1 = 0: c2 = 0: x2 = 0: s1 = 0
Text1.Text = 0: Text2.Text = 0: Text3.Text = 0:
Label1.Caption = " "
End Sub

Private Sub Command3_Click()
End
End Sub

Private Sub form_load()
m1 = 0: m2 = 0: c1 = 0: c2 = 0: x2 = 0: s1 = 0
Text1.Text = " ": Text2.Text = " ": Text3.Text = " "
Label1.Caption = "0"
End Sub

Private Sub Text1_gotfocus()
Text1.Text = " "
End Sub
Private Sub text1_lostfocus()
If Text1.Text = " " Then Text1.Text = "0"
End Sub

Private Sub Text2_gotfocus()
Text2.Text = " "
End Sub
Private Sub text2_lostfocus()
If Text2.Text = " " Then Text2.Text = "0"
End Sub

Private Sub Text3_gotfocus()
Text3.Text = " "
End Sub
Private Sub text3_lostfocus()
If Text3.Text = " " Then Text3.Text = "0"
End Sub

Private Sub Command1_Click()
m1 = CInt(Text1.Text): s1 = CInt(Text2.Text)
c1 = m1 * s1 * 1.005
m2 = CInt(Text3.Text)
c2 = m2 * s1 * 0.005 + c1
x2 = m2 * s1 - c2
Label1.Caption = x2
End Sub
搜索更多相关主题的帖子: 老师 解答 
2008-05-21 15:18
ouzhiguang
Rank: 1
来 自:湖南长沙
等 级:新手上路
威 望:1
帖 子:240
专家分:0
注 册:2007-5-18
收藏
得分:0 
Private Sub Command1_Click()
m1 = CInt(Text1.Text): s1 = CInt(Text2.Text)
c1 = m1 * s1 * 1.005
m2 = CInt(Text3.Text)
c2 = m2 * s1 * 0.005 + c1
x2 = m2 * s1 - c2
Label1.Caption = x2
End Sub
问题出在这里噻
1。如果你在text1,2,3中输入的是整数,那么你的结果就是正确的;反之就是不正确的啊!因为CINT强制转化为整型数据类型啦!
Private Sub Command1_Click()
m1 = val(Text1.Text)
s1 = val(Text2.Text)
c1 = m1 * s1 * 1.005
m2 = val(Text3.Text)
c2 = m2 * s1 * 0.005 + c1
x2 = m2 * s1 - c2
Label1.Caption = x2
End Sub
这样就不会有错了!
2008-05-22 10:20
快速回复:请哪位老师解答!关于计算的程序
数据加载中...
 
   



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

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