《计算器的VB代码.pdf》由会员分享,可在线阅读,更多相关《计算器的VB代码.pdf(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Imports System.Math PublicClass Form1 Public opera As String 记录所要执行的运算soper operator Public rdp As Boolean 记录用户是否已经输入小数点bdot radix point Public equ As Boolean 记录用户是否已经单击等号bequ equalmark Public benum As Double 被操作数 dblacc Public actnum As Double 操作数 dbldes Public result As Double 记录运算结果PrivateSub sub
2、reset()opera=benum=0 actnum=0 rdp=False equ=False OutPut.Text=Pkey.Focus()End Sub PrivateSub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)HandlesMyBase.Load Dim bt(23)As Button Dim i As Integer bt(1)=B1 bt(2)=B2 bt(3)=B3 bt(4)=B4 bt(5)=B5 bt(6)=B6 bt(7)=B7 bt(8)=B8 bt(9)=B9 b
3、t(10)=B0 bt(11)=Ba bt(12)=Bj bt(13)=Bq bt(14)=Bm bt(15)=Bd bt(16)=Be bt(17)=BF bt(18)=Bs bt(19)=Bx bt(20)=Bc bt(21)=BackSpace bt(22)=CE bt(23)=C For i=1 To 23 AddHandler bt(i).Click,New System.EventHandler(AddressOfMe.bt_Click)Next subreset()End Sub PrivateSub formmain_Activated(ByVal sender As Obje
4、ct,ByVal e As System.EventArgs)HandlesMyBase.Activated Pkey.Focus()End Sub PrivateSub bt_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Dim stext As String Dim bclick As Button bclick=sender stext=bclick.Text SelectCase stext Case 1,2,3,4,5,6,7,8,9,0 If equ Then OutPut.Text=End If e
5、qu=False OutPut.Text=OutPut.Text+stext Case.IfNot rdp Then OutPut.Text=OutPut.Text+stext End If Case+,-,*,/,%IfNot OutPut.Text.Equals()Then benum=OutPut.Text OutPut.Text=opera=stext End If Case=rdp=False IfNot equ And Not OutPut.Text.Equals()Then actnum=OutPut.Text End If equ=True SelectCase opera C
6、ase+result=benum+actnum Case-result=benum-actnum Case*result=benum*actnum Case/If actnum=0 then MsgBox”除数不能为零,请重新输入”End if result=benum/actnum Case%If actnum=0 then MsgBox”求余数不能为零,请重新输入”End if result=benum Mod actnum End Select OutPut.Text=result Case+/-If OutPut.Text.Substring(0,1)=-Then OutPut.Tex
7、t=OutPut.Text.Substring(1,OutPut.Text.Length-1)Else OutPut.Text=-+OutPut.Text End If Case C subreset()Case CE OutPut.Text=Case BackSpace If OutPut.Text Then If OutPut.Text.Substring(OutPut.Text.Length-1)=.Then rdp=False End If OutPut.Text=OutPut.Text.Substring(0,OutPut.Text.Length-1)End If Case Sqr Dim m As Integer=OutPut.Text If m=0 Then OutPut.Text=Sqrt(m).ToString End If Case 1/X Dim m As Integer=OutPut.Text If m 0 Then OutPut.Text=(1/m).ToString End If End Select End Sub PrivateSub Pkey_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)HandlesPkey.Click End Sub End Class