实用计算器,源码,eval
时 间:2013-04-22 22:36:50
作 者:th ID:30563 城市:唐山
摘 要:自己想用的计算器,源码共享,用了eval函数,简便实用,完善了功能,支持按钮、键盘混合输入,文本框光标控制,未经详细测试,发现问题请各位指正。
正 文:
图 示:
代 码:
Option Compare Database
Option Explicit
Public Wz As Long
Public Zs As Long
Private Sub Ctl0_Click()
ShuRu (0)
End Sub
Private Sub Ctl1_Click()
ShuRu (1)
End Sub
Private Sub Ctl2_Click()
ShuRu (2)
End Sub
Private Sub Ctl3_Click()
ShuRu (3)
End Sub
Private Sub Ctl4_Click()
ShuRu (4)
End Sub
Private Sub Ctl5_Click()
ShuRu (5)
End Sub
Private Sub Ctl6_Click()
ShuRu (6)
End Sub
Private Sub Ctl7_Click()
ShuRu (7)
End Sub
Private Sub Ctl8_Click()
ShuRu (8)
End Sub
Private Sub Ctl9_Click()
ShuRu (9)
End Sub
Private Sub dian_Click()
ShuRu (".")
End Sub
Private Sub 左_Click()
ShuRu ("(")
End Sub
Private Sub 右_Click()
ShuRu (")")
End Sub
Private Sub 计算式_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Call 计算_Click
End If
End Sub
Private Sub 计算式_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Me.计算式.SelStart = Me.计算式.SelLength
End If
Wz = Me.计算式.SelStart
Zs = Me.计算式.SelLength
Me.字数 = Zs & "/" & Wz & "/" & Len(Me.计算式.Text)
End Sub
Private Sub 计算式_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Wz = Me.计算式.SelStart
Zs = Me.计算式.SelLength
Me.字数 = Zs & "/" & Wz & "/" & Len(Me.计算式.Text)
End Sub
Private Sub Tui_Click()
On Error Resume Next
Dim Jss
Me.计算式.SetFocus
Jss = Me.计算式.Text
Me.计算式.SelStart = Wz
If Zs = 0 Then
Me.计算式 = Left(Jss, Wz - 1) & Mid(Jss, Wz + 1)
If Wz > 0 Then
Wz = Wz - 1
End If
Else
Me.计算式 = Left(Jss, Wz) & Mid(Jss, Wz + Zs + 1)
Zs = 0
End If
Me.计算结果 = ""
Me.大写结果 = ""
Me.计算式.SelStart = Wz
Me.字数 = Zs & "/" & Wz & "/" & Len(Me.计算式.Text)
End Sub
Private Sub 计算_Click()
On Error GoTo tc
Me.计算式.SetFocus
If Me.计算式.Text = "" Then Exit Sub
Dim Jsjg As Double
Dim Lsjl As String
Jsjg = Eval(Me.计算式.Text)
Me.计算结果 = Jsjg
If Jsjg < 1000000000000# Then
Me.大写结果 = GetDXJE(Jsjg)
Else
Me.大写结果 = "数字超出范围,无法显示!"
End If
If IsNull(Me.历史记录) or Me.历史记录 = "" Then
Lsjl = Me.计算式.Text & "=" & Jsjg
Else
Lsjl = Me.计算式.Text & "=" & Jsjg & Chr(13) & Chr(10) & Me.历史记录
End If
Me.历史记录 = Lsjl
Wz = Me.计算式.SelLength
Me.计算式.SelStart = Wz
Zs = 0
Me.字数 = Zs & "/" & Wz & "/" & Len(Me.计算式.Text)
Exit Sub
tc:
MsgBox Err.Description, vbInformation, "错误提示"
Resume Next
End Sub
Private Sub ShuRufh(Fu As String)
Dim Jss
Jss = Me.计算式
If IsNull(Jss) or Jss = "" Then
Me.字数 = ""
Exit Sub
End If
Me.计算式.SetFocus
Me.计算式.SelStart = Wz
If Wz = 0 Then Exit Sub
If Zs > 0 Then
Me.计算式 = Left(Jss, Wz) & Fu & Mid(Jss, Wz + Zs + 1)
Zs = 0
Wz = Wz + 1
Else
Dim MoWei As String
MoWei = Right(Left(Jss, Wz), 1)
If MoWei = "+" or MoWei = "-" or MoWei = "*" or MoWei = "/" or MoWei = "." Then
Me.计算式 = Left(Jss, Wz - 1) & Fu & Mid(Jss, Wz + 1)
ElseIf IsNumeric(MoWei) or MoWei = ")" Then
Me.计算式 = Left(Jss, Wz) & Fu & Mid(Jss, Wz + 1)
Wz = Wz + 1
End If
End If
Me.计算式.SelStart = Wz
Zs = 0
Me.字数 = Zs & "/" & Wz & "/" & Len(Me.计算式.Text)
End Sub
Private Sub ShuRu(Fu As String)
Me.计算结果 = ""
Me.大写结果 = ""
Me.计算式.SetFocus
Me.计算式.SelStart = Wz
Dim Jss
Jss = Me.计算式
If Zs > 0 Then
Me.计算式 = Left(Jss, Wz) & Fu & Mid(Jss, Wz + Zs + 1)
Zs = 0
Else
If IsNull(Jss) or Jss = "" Then
Me.计算式 = Fu
Me.字数 = "0/1/1"
Else
Me.计算式 = Left(Jss, Wz) & Fu & Mid(Jss, Wz + 1)
End If
End If
Wz = Wz + 1
Me.计算式.SelStart = Wz
Zs = 0
Me.字数 = Zs & "/" & Wz & "/" & Len(Me.计算式.Text)
End Sub
Private Sub 计算式_Change()
Me.计算结果 = ""
Me.大写结果 = ""
Zs = Me.计算式.SelLength
End Sub
Private Sub 加_Click()
ShuRufh ("+")
End Sub
Private Sub 减_Click()
ShuRufh ("-")
End Sub
Private Sub 乘_Click()
ShuRufh ("*")
End Sub
Private Sub 除_Click()
ShuRufh ("/")
End Sub
Private Sub 清除计算式_Click()
Me.计算式 = ""
Me.计算结果 = ""
Me.大写结果 = ""
Me.计算式.SetFocus
Me.字数 = ""
Wz = 0
End Sub
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access判断多条明细的配方或订...(11.30)
- 如何让后台数据库在局域网共享时,且...(11.29)
- 【Access月初月末日期设置方法...(11.29)
- 【Access IIF函数嵌套示例...(11.26)
- Access快速开发平台--使用组...(11.25)
- Access快速开发平台--对上传...(11.22)
- Access快速开发平台企业版--...(11.18)
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)