vb入门编程系列问题2

来源:百度知道 编辑:UC知道 时间:2024/05/12 07:53:33
看下面的代码:
Dim storestring As String
Private Sub Command1_Click()
If Command1.Caption = "清除" Then
storestring = Text1.Text
Text1.Text = ""
Command1.Caption = "还原"
Else
Command1.Caption = "还原"
Text1.Text = storestring
Command1.Caption = "清除"
End If
End Sub

但是如果我把它改成两个if语句,为什么他就不能运行了呢?
我是这样改的:
Dim storestring As String

Private Sub Command1_Click()
If Command1.Caption = "清除" Then

storestring = Text1.Text
Text1.Text = ""
Command1.Caption = "还原"
end if

if Command1.Caption = "还原" then
Text1.Text = storestring
Command1.Caption = "清除"
End If
End Sub

请帮忙解答一下~~谢谢!!!

先按程序顺序判断一下:
Dim storestring As String

Private Sub Command1_Click()
If Command1.Caption = "清除" Then ''当条件为真执行下面的当前IF块语句
storestring = Text1.Text
Text1.Text = ""
Command1.Caption = "还原" ''COMMAND1.caption为"还原"
end if

if Command1.Caption = "还原" then ''*****上面的IF块里面已经把COMMAND1.caption改为了"还原"所以这里执行.

Text1.Text = storestring
Command1.Caption = "清除" ''这里又将''COMMAND1.caption该为"清除".程序看上去是没有改变.其实是把CAPTION先改为还原然后又改为清除了.

End If
End Sub

应改为:
Dim storestring As String
Private Sub Command1_Click()
If Command1.Caption = "清除" Then

storestring = Text1.Text
Text1.Text = ""
Command1.Caption = "还原"
Exit Sub
End If

If Command1.Caption = "还原" Then
Text1.Text = storestring
Command1.