vb编写的计算器代码
作者:yutian8802
运行界面:
用到控件有
一个按钮控件数组command1 0-16共 17个 一个frame 一个label 一个文本框
代码如下:
Private Sub Command1_Click(Index As Integer)
Dim jia, jian, cheng, chu As Double
Dim qian, hou As String If Index = 0 Then
If jisuan = 1 Then
Text1.Text = 7
End If
Text1.Text = Text1.Text & 7 jisuan = 0
ElseIf Index = 1 Then
Text1.Text = Text1.Text & 8 ElseIf Index = 2 Then
Text1.Text = Text1.Text & 9 ElseIf Index = 3 Then
Text1.Text = Text1.Text & 4 ElseIf Index = 4 Then
Text1.Text = Text1.Text & 5 ElseIf Index = 5 Then
Text1.Text = Text1.Text & 6 ElseIf Index = 6 Then
Text1.Text = Text1.Text & 1 ElseIf Index = 7 Then
Text1.Text = Text1.Text & 2 ElseIf Index = 8 Then
Text1.Text = Text1.Text & 3
ElseIf Index = 9 Then
Text1.Text = Text1.Text & 0
ElseIf Index = 10 Then
Text1.Text = Text1.Text & "."
ElseIf Index = 11 Then
jian = 0
jia = InStr(Text1.Text, "+")
If InStr(Text1.Text, "-") <> 1 Then jian = InStr(Text1.Text, "-") End If
cheng = InStr(Text1.Text, "*") chu = InStr(Text1.Text, "/")
If geshu(jia, jian, cheng, chu) < 2 Then
If jia Then
qian = Mid(Text1.Text, 1, jia - 1) hou = Mid(Text1.Text, jia + 1, Len(Text1.Text) - jia)
Text1.Text = Val(qian) + Val(hou) End If
If jian And Not jian = 1 Then qian = Mid(Text1.Text, 1, jian - 1) hou = Mid(Text1.Text, jian + 1, Len(Text1.Text) - jian)
Text1.Text = Val(qian) - Val(hou) End If
If cheng Then
qian = Mid(Text1.Text, 1, cheng - 1) hou = Mid(Text1.Text, cheng + 1, Len(Text1.Text) - cheng)
Text1.Text = Val(qian) * Val(hou) End If
If chu Then
qian = Mid(Text1.Text, 1, chu - 1) hou = Mid(Text1.Text, chu + 1, Len(Text1.Text) - chu)
If Val(hou) = 0 Then
Text1.Text = "难道你忘了被除数不能为零,~"
Else
Text1.Text = Val(qian) / Val(hou) End If
End If
If Val(Text1.Text) > -1 And Val(Text1.Text) < 1 And InStr(Text1.Text, ".") Then
Text1.Text = Replace(Text1.Text, ".", "0.")
End If
Else
Text1.Text = "请勿进行多重计算,如:2+3+5或4/8*5" End If
ElseIf Index = 12 Then
Text1.Text = Text1.Text & "/" ElseIf Index = 13 Then
Text1.Text = Text1.Text & "*" ElseIf Index = 14 Then
Text1.Text = Text1.Text & "-" ElseIf Index = 15 Then
Text1.Text = Text1.Text & "+" Else
Text1.Text = ""
End If
End Sub
Private Function geshu(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As
Double)
i = 0
If a > 0 Then
i = i + 1
End If
If b > 0 Then
i = i + 1
End If
If c > 0 Then
i = i + 1
End If
If d > 0 Then
i = i + 1
End If
geshu = i
End Function
本文档为【vb编写的计算器代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。