Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Return without gosub
#11
Code à la Spaghetti Bolognese...

Yummi Smile
Reply
#12
JANESH,
One of the most common reasons for getting the "return without gosub" error is because you entered the subroutine from the line above. That is, the code immediately before the subroutine code somehow falls through and enters the subroutine. Then when it hits the Return instruction, it issues the error because you never did a GOSUB to the subroutine.

The code immediately before a subroutine label should be a GOTO, a RETURN, a SYSTEM, or an END. You can't fall through to the next instructions after any of there.

So look at the code just before the label which starts your subroutines.

Another possibility is that you did a GOTO to the subroutine instead of a GOSUB.
*****
Reply
#13
Or a GOTO jumping outside a subroutine from inside it.
Antoni
Reply
#14
Try shift+F5.
Reply
#15
I came back to the GOSUB in some special cases, when the SUB is getting big and I don't want to create one more SUB just for something which is used only in the sub. I find the program easier to read when the name of the subs mean something, e.g. Init.Object, etc...

The code is then structured that way:

Code:
SUB Make.Icecream

Get Cream.Scent1
Get Cream.Scent2
GOSUB Blend

Get ChocolatePowder
Cream=Cream+Chocolate

EXIT SUB        ' End of the Sub's main part

Blend:            ' Begin of the Sub's sub
Cream=Cream.Scent1+Cream.Scent2
RETURN          ' End of the Sub's sub

END SUB         ' End of the Sub

The only problem when you get to big programs of this kind is that a day comes when you cannot compile the prog because it's too big :lol:
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#16
GOSUB? This is old stuff....

I just rediscovered
ON expression GOTO label1,label2.....
:rotfl:
Antoni
Reply
#17
Quote:Or a GOTO jumping outside a subroutine from inside it.
Actually, such a GOTO would create an unsatisfied RETURN on the GOSUB/RETURN stack, which normally would not cause a "return without gosub" error.

A more probable cause is doing a GOTO into the middle of a subroutine to reuse the last part of its code, and forgetting that to do such a crazy thing you need to enter this last part with a GOSUB.

And yes Antoni, the ON GOTO statement was the way in older Basic's of doing a CASE-like statement before CASE was introduced into the language. Some people still use it today out of habit.
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)