这是一个简易计算器的VB代码,下面是这个计算器的界面,有一个文本输入框和16个按钮 Public Class Form1 Dim OperatorState As Integer Dim data1 As Integer Dim result As Integer Dim data2 As Integer ’下面是0~9十个按钮的点击事件 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = TextBox1.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.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.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.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.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.Text = "" 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 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 sender 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 Sub End Class 本文来源:https://www.wddqw.com/doc/feba522e2af90242a895e5bd.html