【发布时间】:2012-01-09 04:01:45
【问题描述】:
我的程序中有函数在到达返回行后停止,但我需要函数继续运行,以防我希望函数返回更改。
是否有解决方法或强制函数在返回后继续执行的方法?
我制作了一个测试程序来演示这个问题。它是一个仅包含一个按钮的表单。
这里是源代码:
Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click
If testFunction() = True Then
MsgBox("It returned True!")
Else
MsgBox("It returned False!")
End If
End Sub
Function testFunction() As Boolean
Dim testVariable As Boolean = True
Return False
If testVariable = True Then
Return True
End If
End Function
消息框总是显示“它返回 False”,如果它继续按照我想要的方式处理代码,它会返回 true。
【问题讨论】:
-
在 testFunction() 函数中声明 testVariable 变量后返回 false 。这就是它总是返回 false。你必须更改该序列
-
你误解了我的问题。我是故意这样做的。我想要一种方法让它继续追随
Return False