使用函数递归调用方式编写一个计算器程序,分别能够实现加,减,乘,除四种运算

2025-05-09 02:43:17
推荐回答(2个)
回答1:

用什么操作环境?
Option Explicit
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 = Val(Text1.Text)
End If
s = Index
End Sub
Option Explicit
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 = Val(Text1.Text)
End If
s = Index
End Sub

回答2:

百度一下 百度一下