Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Return without gosub
#1
what exactly is this stupid error ???
The first time i run the program, it works fine, then the second time i start it, it says RETURN without GOSUB
If i close QB and then Start it Again and RUN, it works fine, but then the second time, it shows the error again

WHY!!!????
Reply
#2
QB encountered a RETURN statement while no GOSUB was called. That's a logical problem using GOSUB.

Anway, to solve this, make sure that QB can only access the RETURN when a GOSUB was called. The simplest is to make your program according to the following scheme:

Code:
'All of your source code go here

'Here is a GOSUB
GOSUB dosomething

'Perhaps more source code

END 'prevents the program from running into RETURN statements
'without having called GOSUB

dosomething:
'do something code
RETURN
Reply
#3
what if you dont want to end your program ?
or do you just type it in the end ?
Reply
#4
It just is the scheme of your program.

Now I'll try to explain in text:

1. Put all your sub-code which the GOSUBs refer to all the way back of your code. Thus, at the end.
2. Your source code should be at the beginning of the file.
3. Between those two partitions you should stop the QB IDE from preceeding to all those labels the GOSUB refers to.

Just a little example:

Code:
INPUT "Please enter the radius of the circle", radius#
A# = 0
GOSUB calcradius
PRINT "A ="; A#

END
'I put the end here so that the program, after having finished, doesn't go to the sub-codes, where the error will spawn when it encounters a RETURN.

calcradius:
A# = 3.141592654# * (radius# ^ 2)
RETURN


I don't use GOSUB much, but I'd advice you learning how SUBs and FUNCTIONs work.

But...., if you still want info about GOSUB, you can also look in QBOHO: http://qbasicnews.com/qboho/qckgosub.shtml
Reply
#5
Ok..last few questions..lol..

1: My program uses DOZENS of GOSUBs [cant use subs and functions in this project]..now it gets really confusing, which RETURN for which GOSUB.How do i keep track on this ? or rather, is there an easier way to do so ?
2: For this same program, i want to use a command like GOSUB but without the loop. I Cant use GOTO though. The code you gave about the END before the RETURN makes sence but is there an easier way ?
Reply
#6
Answer to both questions: try SUB and FUNCTION. Wink lol

You can find about them here:

http://qbasicnews.com/qboho/qcksub.shtml
and
http://qbasicnews.com/qboho/qckfunction.shtml

You don't need any return then. QB automatically keeps track of it.

Really... try it Smile
Reply
#7
lol..ok :rotfl:
Reply
#8
Quote:Ok..last few questions..lol..

1: My program uses DOZENS of GOSUBs [cant use subs and functions in this project]..now it gets really confusing, which RETURN for which GOSUB.How do i keep track on this ? or rather, is there an easier way to do so ?
2: For this same program, i want to use a command like GOSUB but without the loop. I Cant use GOTO though. The code you gave about the END before the RETURN makes sence but is there an easier way ?
If you really want to use lots of GOSUBs and your finding it hard to follow, maybe you need to structure you code better.

Indentation, and lots of white space can make code much more readable, and don't forget to add remarks so you know what the different parts of the code are doing. (like a remark after each RETURN)

e.g.
Code:
'some code
.
.
.
GOSUB initial
.
.
.
GOSUB main
.
.
.
END

initial:
   'initial code here
   .
   .
   .
RETURN 'initial

main:
   'main code here
   .
   .
   .
   .
RETURN 'main

And try not to do things like this: (having one RETURN for two different GOSUBs as it can confuse things)
Code:
drawscreen:
   .
   .
   .
drawmenubar:
   .
   .
   .
RETURN
url=http://www.spreadfirefox.com/?q=affiliates&id=60131&t=79][Image: safer.gif][/url]
END OF LINE.
Reply
#9
Sounds like you need to check out DO...LOOP.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#10
Sounds like spaghetti carbonara Big Grin
Antoni
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)