注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

你所要的信息,请收入囊中。

 
 
 

日志

 
 

用VB编写简易计算器代码  

2017-02-08 14:43:57|  分类: 计算机 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

用VB编写简易计算器代码

用VB编写简易计算器代码 - 主人 - 主人博客
 
Dim Cleardisplay As Boolean
Dim shuzi1 As Double, shuzi2 As Double
Dim Yunsuanfu As String

Private Sub Command1_Click()
result.Caption = ""
End Sub

Private Sub Command2_Click()
If InStr(result.Caption, ".") Then
Exit Sub
Else
result.Caption = result.Caption + "."
End If
End Sub

Private Sub Command3_Click()
result.Caption = -Val(result.Caption)
End Sub

Private Sub Command4_Click()
If Val(result.Caption) <> 0 Then
result.Caption = 1 / (Val(result.Caption))
Else
Exit Sub
End If
End Sub

Private Sub Command5_Click()
shuzi1 = Val(result.Caption)
Yunsuanfu = "+"
result.Caption = ""
End Sub

Private Sub Command6_Click()
shuzi1 = Val(result.Caption)
Yunsuanfu = "-"
result.Caption = ""
End Sub

Private Sub Command7_Click()
shuzi1 = Val(result.Caption)
Yunsuanfu = "*"
result.Caption = ""
End Sub

Private Sub Command8_Click()
shuzi1 = Val(result.Caption)
Yunsuanfu = "/"
result.Caption = ""
End Sub

Private Sub Command9_Click()
Dim jieguo As Double
On Error GoTo Errhandle
shuzi2 = Val(result.Caption)
If Yunsuanfu = "+" Then jieguo = shuzi1 + shuzi2
If Yunsuanfu = "-" Then jieguo = shuzi1 - shuzi2
If Yunsuanfu = "*" Then jieguo = shuzi1 * shuzi2
If Yunsuanfu = "/" And shuzi2 <> 0 Then jieguo = shuzi1 / shuzi2
If jieguo < 1 And jieguo > -1 Then
result.Caption = "0" & Str(jieguo)
Cleardisplay = True
Else
result.Caption = jieguo
End If
Exit Sub
Errhandle:
  result.Caption = "ERROR"
  Cleardisplay = True
End Sub

Private Sub digit_Click(Index As Integer)
If Cleardisplay Then
result.Caption = ""
Cleardisplay = False
Else
result.Caption = result.Caption + digit(Index).Caption
End If
End Sub

Private Sub Form_Load()
Cleardisplay = False
result.FontSize = 40
End Sub

Private Sub result_Change()
If Len(result.Caption) >= 26 Then
result.FontSize = 12
ElseIf Len(result.Caption) >= 17 Then
result.FontSize = 15
ElseIf Len(result.Caption) > 10 Then
result.FontSize = 25
Else
result.FontSize = 40
End If
End Sub

主人推荐阅读:
  评论这张
 
阅读(13)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017