vb 编辑计算器的一个疑点
来源:百度知道 编辑:UC知道 时间:2024/06/20 12:06:13
Dim flag As Boolean
Dim op
Dim opt2
Dim opt1
Private Sub clear_Click()
Text1.Text = ""
opt1 = ""
opt2 = ""
flag = False
End Sub
Private Sub Command1_Click(Index As Integer)
If flag = False Then
Text1.Text = Command1(Index).Caption
flag = True
Else
Text1.Text = Text1.Text & Command1(Index).Caption
End If
End Sub
Private Sub Command2_Click(Index As Integer)
opt1 = Val(Text1.Text)
Text1.Text = ""
op = Command2(Index).Index
End Sub
Private Sub Command4_Click()
opt2 = Val(Text1.Text)
Select Case op
Case Is = 3
opt1 = opt1 - opt2 '这里把opt1改成text1.text 也可以 这样可以把Text1.Text = opt1去掉了
Case 2
opt1 = opt1 - -opt2
Case 1
opt1 = opt1 * opt2
Case 0
If opt2 = 0 Then
MsgBox "分母不能为零", vbOKCancel
Exit Sub
Else
opt1 =
Dim op
Dim opt2
Dim opt1
Private Sub clear_Click()
Text1.Text = ""
opt1 = ""
opt2 = ""
flag = False
End Sub
Private Sub Command1_Click(Index As Integer)
If flag = False Then
Text1.Text = Command1(Index).Caption
flag = True
Else
Text1.Text = Text1.Text & Command1(Index).Caption
End If
End Sub
Private Sub Command2_Click(Index As Integer)
opt1 = Val(Text1.Text)
Text1.Text = ""
op = Command2(Index).Index
End Sub
Private Sub Command4_Click()
opt2 = Val(Text1.Text)
Select Case op
Case Is = 3
opt1 = opt1 - opt2 '这里把opt1改成text1.text 也可以 这样可以把Text1.Text = opt1去掉了
Case 2
opt1 = opt1 - -opt2
Case 1
opt1 = opt1 * opt2
Case 0
If opt2 = 0 Then
MsgBox "分母不能为零", vbOKCancel
Exit Sub
Else
opt1 =
op是全局变量可以在整个过程中调用 而Command2(Index).Index 获得的值是局部变量只能在Private Sub Command2_Click(Index As Integer)中调用
Dim flag As Boolean
Dim op
Dim opt2
Dim opt1
Dim a
Private Sub clear_Click()
Text1.Text = ""
opt1 = ""
opt2 = ""
flag = False
End Sub
Private Sub Command1_Click(Index As Integer)
If flag = False Then
Text1.Text = Command1(Index).Caption
flag = True
Else
Text1.Text = Text1.Text & Command1(Index).Caption
End If
End Sub
Private Sub Command2_Click(Index As Integer)
opt1 = Val(Text1.Text)
Text1.Text = ""
op = Command2(Index).Index
End Sub
Private Sub Com