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、小数点按钮、加法、减法、乘法、除法和等于按钮。用户可以点击按钮输入数字和操作符,并在文本框中看到输入的结果。点击等于按钮后,计算器将执行所选操作,并显示结果在文本框中。用户也可以点击清除按钮清空文本框中的内容。
版权声明:本文标题:VB简易计算器代码 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1705984821h496714.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论