VB简单计算器编程代码(附图)

2022-05-19 15:29:14   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《VB简单计算器编程代码(附图)》,欢迎阅读!
计算器,附图,编程,代码,简单


Public sum As Double Public k As String "定义全局变量

Private Sub Command1_Click(Index As Integer) Select Case Index Case 1

Text1.Text = Text1.Text & 1 Case 2

Text1.Text = Text1.Text & 2 Case 3

Text1.Text = Text1.Text & 3 Case 4

Text1.Text = Text1.Text & 4 Case 5

Text1.Text = Text1.Text & 5 Case 6

Text1.Text = Text1.Text & 6 Case 7

Text1.Text = Text1.Text & 7 Case 8

Text1.Text = Text1.Text & 8 Case 9

Text1.Text = Text1.Text & 9 Case 0

Text1.Text = Text1.Text & 0 Case 10

Text1.Text = Text1.Text & "."


End Select End Sub

Private Sub Command2_Click() sum = Text1.Text Text1.Text = "" k = "+" End Sub

Private Sub Command3_Click() sum = Text1.Text Text1.Text = "" k = "-" End Sub

Private Sub Command4_Click() sum = Text1.Text Text1.Text = "" k = "*" End Sub

Private Sub Command5_Click() sum = Text1.Text Text1.Text = "" k = "/" End Sub

Private Sub Command6_Click() Dim a As Double a = Text1.Text If k = "+" Then sum = sum + a Text1.Text = sum ElseIf k = "-" Then sum = sum - a Text1.Text = sum ElseIf k = "*" Then sum = sum * a Text1.Text = sum ElseIf k = "/" Then sum = sum / a Text1.Text = sum End If End Sub


Private Sub Command7_Click() Unload Form1 End Sub

Private Sub Command8_Click() Text1.Text = "" End Sub




本文来源:https://www.wddqxz.cn/62a1b7e59b89680203d8253e.html