I have functions in my program that stop after it reaches a Return line but I need the function to continue in case what I want the function to return changes.
Is there a workaround for this or a way to force the function to continue after a return?
I made a Test Program to demonstrate the problem. It is a Form that contains only a button.
Here is the source code:
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
The messagebox always says “It returned False” when if it continued going through the code like I want it to it would have returned true.
You already have a flag variable set up, so use it!
Also, don’t ever use
= Trueor= Falsein comparisons.= Trueis 100% redundant andx = Falseshould beNot x.EDIT: Sorry, that wasn’t clear.
is always* the same as