| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 993 人关注过本帖
标题:简易计算器
取消只看楼主 加入收藏
随爱飘扬
Rank: 1
来 自:中国南昌
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-9-22
收藏
 问题点数:0 回复次数:2 
简易计算器
今年刚学VB,网上借鉴了一些,编了一个计算器,心中有小小的一点成就感,大家看看哦,给我提点建议哦,谢谢哦。
Dim s1!, s3!, s2$, s4$, a%, b%, c%

Private Sub command1_click(Index As Integer)
Text1.Text = Text1.Text & Command1(Index).Caption
End Sub

 

Private Sub Command2_Click(Index As Integer)
s1 = Val(Text1.Text)
s2 = command2(Index).Caption

Text1.Text = ""
End Sub
Private Sub Command13_Click(Index As Integer)


s4 = Command13(Index).Caption

End Sub

 

Private Sub Command3_Click()
s3 = Val(Text1.Text)
Select Case s4
Case "cos"

Text1.Text = Cos(s3)

 

Case "1/x"
Text1.Text = 1 / s3
Case "rnd"
Text1.Text = Rnd(s3)
Case "sin"
Text1.Text = Sin(s3)
Case "tan"
Text1.Text = Tan(s3)
Case "exp"
Text1.Text = Exp(s3)
Case "abs"
Text1.Text = Abs(s3)
Case "log"
Text1.Text = Log(s3)
End Select
Select Case s2
Case "+"
Text1.Text = s1 + s3
Case "-"
Text1.Text = s1 - s3
Case "*"
Text1.Text = s1 * s3
Case "/"
Text1.Text = s1 / s3
End Select
End Sub
Private Sub Command200_Click()
Text1.Text = ""
End Sub
Private Sub Command6_Click()
 If Text1.Text = "" Then
Exit Sub
End If
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub

Private Sub Command5_Click()
  
Text1.Text = Text1.Text + "."
If (InStr(Text1.Text, ".") = 1) Then '第一位不能为小数
 Text1.Text = ""
 End If
If InStr(Text1.Text, ".") < Len(Text1.Text) Then
 '防止出现两个小数点
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
  
End If
  
End Sub

Private Sub Command7_Click()
If Left(Text1.Text, 1) <> "-" Then
Text1.Text = "-" & Text1.Text
 Else
 Text1.Text = Right(Text1.Text, Len(Text1.Text) - 1)
End If
End Sub
Private Sub Command8_Click()
Text1.Text = Val(Text1.Text) * Val(Text1.Text)
End Sub
Private Sub Command9_Click()
Text1.Text = Text1.Text * Text1.Text * Text1.Text
End Sub
Private Sub Command10_Click()
Text1.Text = Sqr(Val(Text1.Text))
End Sub
Private Sub Command11_Click()
Text1.Text = Sqr(Val(Text1.Text))
End Sub

Private Sub Command30_Click()
Timer1.Enabled = True
Command30.Visible = False
Command31.Visible = True
a = Val(Text7.Text)
b = Val(Text6.Text)
c = Val(Text5.Text)
End Sub
Private Sub Command31_Click()
Timer1.Enabled = False
Command30.Visible = True
Command31.Visible = False
Command32.Visible = True
Command33.Visible = True
Command34.Visible = True
End Sub
Private Sub Command32_click()
If (a < 59) Then
a = a + 1
Else
a = 0
End If
Text7 = a
End Sub
Private Sub Command33_click()
If (b < 59) Then
b = b + 1
Else
b = 0
End If
Text6 = b
End Sub
Private Sub Command34_click()
If (c < 23) Then
c = c + 1
Else
c = 0
End If
Text5 = c
End Sub
Private Sub Timer1_Timer()
a = a + 1
If a > 59 Then
a = 0
b = b + 1
End If
If b > 59 Then
b = 0
c = c + 1
End If
If c > 23 Then
c = 0
b = 0
a = 0
End If


Text7 = a
Text6 = b
Text5 = c
End Sub
        其计算器的蛮多功能都有了,自己也感觉要是再有括号,开立方,三角函数用度来表示,π的计算,LOG 2底,X的Y字方的话,就更好了,但是怎么搞也弄不出来                                                           
搜索更多相关主题的帖子: 计算器 
2010-09-22 16:49
随爱飘扬
Rank: 1
来 自:中国南昌
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-9-22
收藏
得分:0 
回复 楼主 随爱飘扬
恩,感觉加括号有涉及一些知识

纵使没有世界了,还有编程!
2010-09-23 14:30
随爱飘扬
Rank: 1
来 自:中国南昌
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-9-22
收藏
得分:0 
回复 2楼 风吹过b
哈哈,找不到,我再找下,到时看下网上是怎么做的

纵使没有世界了,还有编程!
2010-09-23 14:32
快速回复:简易计算器
数据加载中...
 
   



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

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