admin 管理员组

文章数量: 887021


2024年1月23日发(作者:human stacking)

VB简易计算器代码

以下是一个简单的VB计算器代码:

```

Public Class Form1

Dim firstNum As Double ' 第一个数字

Dim secondNum As Double ' 第二个数字

Dim operation As Integer ' 1-加法,2-减法,3-乘法,4-除法

Private Sub Button0_Click(sender As Object, e As EventArgs)

Handles

= & "0"

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs)

Handles

= & "1"

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs)

Handles

= & "2"

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs)

Handles

= & "3"

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs)

Handles

= & "4"

End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs)

Handles

= & "5"

End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs)

Handles

= & "6"

End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs)

Handles

= & "7"

End Sub

Private Sub Button8_Click(sender As Object, e As EventArgs)

Handles

= & "8"

End Sub

Private Sub Button9_Click(sender As Object, e As EventArgs)

Handles

= & "9"

End Sub

Private Sub ButtonDot_Click(sender As Object, e As EventArgs)

Handles

If Not ns(".") Then

= & "."

End If

End Sub

Private Sub ButtonAdd_Click(sender As Object, e As EventArgs)

Handles

firstNum = ()

= ""

operation = 1

End Sub

Private Sub ButtonSubtract_Click(sender As Object, e As

EventArgs) Handles

firstNum = ()

= ""

operation = 2

End Sub

Private Sub ButtonMultiply_Click(sender As Object, e As

EventArgs) Handles

firstNum = ()

= ""

operation = 3

End Sub

Private Sub ButtonDivide_Click(sender As Object, e As

EventArgs) Handles

firstNum = ()

= ""

operation = 4

End Sub

Private Sub ButtonClear_Click(sender As Object, e As

EventArgs) Handles

= ""

End Sub

Private Sub ButtonEquals_Click(sender As Object, e As

EventArgs) Handles

Dim result As Double

secondNum = ()

Select Case operation

Case 1

result = firstNum + secondNum

Case 2

result = firstNum - secondNum

Case 3

result = firstNum * secondNum

Case 4

result = firstNum / secondNum

End Select

= ng

End Sub

End Class

```

这个计算器包括数字按钮0-9、小数点按钮、加法、减法、乘法、除法和等于按钮。用户可以点击按钮输入数字和操作符,并在文本框中看到输入的结果。点击等于按钮后,计算器将执行所选操作,并显示结果在文本框中。用户也可以点击清除按钮清空文本框中的内容。


本文标签: 按钮 点击 文本框 计算器 结果