vb怎么设计个简单的计算器

来源:百度知道 编辑:UC知道 时间:2024/05/23 16:26:20
只要一个简单的计算器,加减乘除的,数字键是控件数组的。
谢谢,给个代码就行。

给你个稍微简单一点的。。。。用控件数组的。
Dim v As Boolean
Dim s As Integer
Dim x As Double
Dim y As Double
Private Sub Command1_Click(Index As Integer)
If Form1.Tag = "s" Then
If Index = 10 Then
Text1.Text = "0."
Else
Text1.Text = Command1(Index).Caption
End If
Form1.Tag = ""
Else
Text1.Text = Text1.Text & Command1(Index).Caption
End If
End Sub

Private Sub Command2_Click(Index As Integer)
Form1.Tag = "s"
If v Then
x = Val(Text1.Text)
v = Not v
Else
y = Val(Text1.Text)
Select Case s
Case 0
Text1.Text = x + y
Case 1
Text1.Text = x - y
Case 2
Text1.Text = x * y
Case 3
If y <> 0 Then
Text1.Text = x / y
Else
MsgBox ("不能以0为除数")
Text1.Text = x
v = False
End If
Case 4
y = 0
v = False
End Select
x