资源描述
这是一个简易计算器的VB代码,下面是这个计算器的界面,有一个文本输入框和16个按钮叫筒附算器一匡叵PublicClassForm1DimOperatorStateAsIntegerDimdata1AsIntegerDimresultAsIntegerDimdata2AsInteger下面是09十个按钮的点击事件PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.ClickTextBox1.Text=TextBox1.Text+1EndSubByValeAsSystem.EventArgs)HandlesByValeAsSystem.EventArgs)HandlesPrivateSubButton2_Click(ByValsenderAsSystem.Object,Button2.ClickTextBox1.Text=TextBox1.Text+2EndSubPrivateSubButton3_Click(ByValsenderAsSystem.Object,Button3.ClickTextBox1.Text=TextBox1.Text+3EndSubPrivateSubButton4_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton4.ClickTextBox1.Text=TextBox1.Text+4EndSubPrivateSubButton5_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton5.ClickTextBox1.Text=TextBox1.Text+5EndSubPrivateSubButton6_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton6.ClickTextBox1.Text=TextBox1.Text+6EndSubPrivateSubButton7_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton7.ClickTextBox1.Text=TextBox1.Text+7EndSubPrivateSubButton8_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton8.ClickTextBox1.Text=TextBox1.Text+8EndSubPrivateSubButton9_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton9.ClickTextBox1.Text=TextBox1.Text+9EndSubPrivateSubButton10_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton10.ClickTextBox1.Text=TextBox1.Text+0EndSub下面是清除键的代码PrivateSubButton15_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton15.ClickTextBox1.Text=EndSub下面是加减乘除四个按钮的代码PrivateSubButton11_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton11.Clickdata1=Val(TextBox1.Text)OperatorState=1TextBox1.Text=EndSubPrivateSubButton12_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton12.Clickdata1=Val(TextBox1.Text)OperatorState=2TextBox1.Text=EndSubPrivateSubButton13_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton13.Clickdata1=Val(TextBox1.Text)OperatorState=3TextBox1.Text=EndSubPrivateSubButton14_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton14.Clickdata1=Val(TextBox1.Text)OperatorState=4TextBox1.Text=EndSub下面是等于号的的代码PrivateSubButton16_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton16.Clickdata2=Val(TextBox1.Text)If(OperatorState=1)Thenresult=data1+data2EndIfIf(OperatorState=2)Thenresult=data1-data2EndIfIf(OperatorState=3)Thenresult=data1*data2EndIfIf(OperatorState=4)Thenresult=data1/data2EndIfTextBox1.Text=Str(result)EndSubEndClass
展开阅读全文