Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return without GoSub 1

Status
Not open for further replies.

hinchdog

Programmer
Feb 14, 2001
380
US
what does this error mean?
 
from vb4 help file (all i have on this computer)

A Return statement must have a corresponding GoSub statement. This error has the following cause and solution:

You have a Return statement that cannot be matched with a GoSub statement.

Make sure your GoSub statement was not unintentionally deleted.

Unlike For...Next, While...Wend, and Sub...End Sub, which are matched at compile time, GoSub and Return are matched at run time.

Dragnut
 
Perhaps your sub is at the end of a subroutine and program flow drops into it rather than exiting the sub. For instance:
Code:
Private Sub Command1_Click()
If flag = True Then GoSub FlagMe
MsgBox "Flag is not true"
FlagMe:
MsgBox "Flag is true"
Return
End Sub
You would want to provide a way to exit the sub before the flow reached the "FlagMe" line label:
Code:
Private Sub Command1_Click()
If flag = True Then GoSub FlagMe
MsgBox "Flag is not true"
Exit Sub
FlagMe:
MsgBox "Flag is true"
Return
End Sub
BTW: Most VB programmers have never used
Code:
On Gosub
. It works but it isn't very kosher.
VCA.gif
 
i got it when i had a return in the errorhandler. i was trying to say return to the place that called the sub. i changed it to "exit sub" instead and now it's fine. thanks for the explanation though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top