VB实现简易计算器源码

上传人:我*** 文档编号:135989954 上传时间:2020-06-22 格式:DOC 页数:6 大小:28.50KB
返回 下载 相关 举报
VB实现简易计算器源码_第1页
第1页 / 共6页
VB实现简易计算器源码_第2页
第2页 / 共6页
VB实现简易计算器源码_第3页
第3页 / 共6页
VB实现简易计算器源码_第4页
第4页 / 共6页
VB实现简易计算器源码_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《VB实现简易计算器源码》由会员分享,可在线阅读,更多相关《VB实现简易计算器源码(6页珍藏版)》请在金锄头文库上搜索。

1、fuhao存储运算符,x存储第一个数,y存储第二个数,z存储结果,flag用来标识是否连续作运算flag2 用来标识是否执行过等于操作Dim fuhao As String, x As Single, y As Single, z As String, flag As Integer, flag2 As Integer执行计算器退格操作Private Sub backs_Click() If Text1.Text Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) Else Text1.Text = Exit Sub End IfEn

2、d SubPrivate Sub c_Click() 将计算器所有值全部置 0Text1.Text = x = 0y = 0End SubPrivate Sub ce_Click() 将计算器输入的当前值置 0Text1.Text = y = 0End Sub点击0-9数字Private Sub Command14_Click(Index As Integer) If flag2 = 1 Then flag为1时,表示执行过等于操作,需要清空之前的计算结果 Text1.Text = flag2 = flag2 + 1 End If If Left(Text1.Text, 1) = 0 And

3、InStr(Text1.Text, .) Then 只能输入一个.,输入的数开头不能为0 Text1.Text = Text1.Text & Index ElseIf Left(Text1.Text, 1) = 0 And Text1.Text Then If Index = 0 Then Text1.Text = 0 ElseIf Index 0 Then Print ddddd Text1.Text = Right(Text1.Text & Index), 1) End If Else Text1.Text = Text1.Text & Index End IfEnd Sub取倒数运算Pr

4、ivate Sub daoshu_Click() flag2 = 1 If Val(Text1.Text) 0 Then 分母不能为0 z = 1 / Text1.Text 取倒数 Else MsgBox 分母不能为0!, vbCritical, 错误提示 End If If Left(Val(z), 1) = . Then 将.#转成0.# z = 0 & Val(z) ElseIf Left(Val(z), 2) = -. Then 将-.#转成-0.# z = -0. & Right(Val(z), Len(z) - 2) End If Text1.Text = zEnd Sub开根号运

5、算Private Sub kaigen_Click() flag2 = 1 If Text1.Text Then If Val(Text1.Text) = 0 Then z = Text1.Text (1 / 2) 开根号运算 Else MsgBox 负数不能开根号!, vbCritical, 错误提示 End If End If If Left(Val(z), 1) = . Then 将.#转成0.# z = 0 & Val(z) ElseIf Left(Val(z), 2) = -. Then 将-.#转成-0.# z = -0. & Right(Val(z), Len(z) - 2) E

6、nd If Text1.Text = zEnd Sub百分号运算,公式A ? B % = A (1 + B/100) or A + (A B/100)Private Sub quyu_Click() flag2 = 1 z = x * (Val(Text1.Text) / 100) If Left(Val(z), 1) = . Then 将.#转成0.# z = 0 & Val(z) ElseIf Left(Val(z), 2) = -. Then 将-.#转成-0.# z = -0. & Right(Val(z), Len(z) - 2) End If Text1.Text = z End

7、Sub取负运算Private Sub zf_Click() flag2 = 1 If Val(Text1.Text) Then Text1.Text = -(Text1.Text) ElseIf Left(Text1.Text, 1) = - Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) ElseIf Text1.Text = 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) Else Text1.Text = - & Text1.Text End IfEnd S

8、ub加法运算Private Sub plus_Click() If flag = 0 Then flag = flag + 1 x = Val(Text1.Text) fuhao = + Text1.Text = Else If fuhao = - Then 连续运算操作 x = x - Val(Text1.Text) ElseIf fuhao = * Then x = x * Val(Text1.Text) ElseIf fuhao = / Then If Val(Text1.Text) 0 Then x = x / Val(Text1.Text) Else MsgBox 除数不能为0, v

9、bCritical, 错误提示 End If Else x = x + Val(Text1.Text) Print x & ccc End If fuhao = + Text1.Text = End IfEnd Sub减法运算Private Sub jian_Click() If flag = 0 Then flag = flag + 1 x = Val(Text1.Text) fuhao = - Text1.Text = Else If fuhao = + Then x = x + Val(Text1.Text) ElseIf fuhao = * Then x = x * Val(Text1

10、.Text) ElseIf fuhao = / Then If Val(Text1.Text) 0 Then x = x / Val(Text1.Text) Else MsgBox 除数不能为0, vbCritical, 错误提示 End If Else x = x - Val(Text1.Text) End If fuhao = - Text1.Text = End IfEnd Sub乘法运算Private Sub chen_Click() If flag = 0 Then flag = flag + 1 x = Val(Text1.Text) fuhao = * Text1.Text =

11、Else If fuhao = + Then x = x + Val(Text1.Text) Print x & bbbb ElseIf fuhao = - Then x = x - Val(Text1.Text) ElseIf fuhao = / Then If Val(Text1.Text) 0 Then x = x / Val(Text1.Text) Else MsgBox 除数不能为0, vbCritical, 错误提示 End If Else x = x * Val(Text1.Text) End If fuhao = * Text1.Text = End IfEnd Sub除法运算Private Sub chu_Click() If flag = 0 Then flag = flag + 1 x = Val(Text1.Text) fuhao = / Text1.Text = Else If fuhao = + Then x = x + Val(Text1.Text) ElseIf fuhao = - Then x = x - Val(Text1.Text) ElseIf fuhao

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 事务文书

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号