《VB简易计算器代码(7页).doc》由会员分享,可在线阅读,更多相关《VB简易计算器代码(7页).doc(8页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-这是一个简易计算器的VB代码,下面是这个计算器的界面,有一个文本输入框和16个按钮Public Class Form1 Dim OperatorState As Integer Dim data1 As Integer Dim result As Integer Dim data2 As Integer下面是09十个按钮的点击事件 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = TextBox1
2、.Text + 1 End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = TextBox1.Text + 2 End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox1.Text = TextBox1
3、.Text + 3 End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox1.Text = TextBox1.Text + 4 End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click TextBox1.Text = TextBox1
4、.Text + 5 End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click TextBox1.Text = TextBox1.Text + 6 End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click TextBox1.Text = TextBox1
5、.Text + 7 End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click TextBox1.Text = TextBox1.Text + 8 End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click TextBox1.Text = TextBox1
6、.Text + 9 End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click TextBox1.Text = TextBox1.Text + 0 End Sub下面是清除键的代码 Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click TextBox1.Te
7、xt = End Sub下面是加减乘除四个按钮的代码 Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click data1 = Val(TextBox1.Text) OperatorState = 1 TextBox1.Text = End Sub Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
8、 Button12.Click data1 = Val(TextBox1.Text) OperatorState = 2 TextBox1.Text = End Sub Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click data1 = Val(TextBox1.Text) OperatorState = 3 TextBox1.Text = End Sub Private Sub Button14_Click(ByVal sen
9、der As System.Object, ByVal e As System.EventArgs) Handles Button14.Click data1 = Val(TextBox1.Text) OperatorState = 4 TextBox1.Text = End Sub下面是等于号的的代码Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click data2 = Val(TextBox1.Text) If (OperatorState = 1) Then result = data1 + data2 End If If (OperatorState = 2) Then result = data1 - data2 End If If (OperatorState = 3) Then result = data1 * data2 End If If (OperatorState = 4) Then result = data1 / data2 End If TextBox1.Text = Str(result) End SubEnd Class第 8 页-
限制150内