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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Going between main program and sub

Status
Not open for further replies.

THEMAN101

Programmer
Apr 29, 2003
44
US
i have a main program and i have some subs. IN my main program i have line number 10. When i run a sub, when it finishes i want it to go to line 10 of the main program. How do you get a sub to go to the main program.

THANKS

THEMAN101
 
Wouldn't recommend this but...
use GOSUB 10. I think :)

I really don't use this statement. Maybe you could post your code so we can help you do your prog. in a better way.

Actually, programs containing GOSUB/GOTO are considered to be bad(No offense meant) :D
 
You can't, the only thing you can do, is use EXIT SUB to end the sub prematurely. Then, if another sub did not call it, it will return to the main prog right after where it was last called.
 
quebasic2 is correct. You can't simply tell a sub to specifically goto to a line lable in the main (unless, if memory serves, it is an error trapping code.)

When you CALL sub-name the next line is not execuited until the EXIT SUB was reached. So my suggestion is to create a "global" variable; in the "sub"...change it to something else like gblGoto10 = -1, THEN in the line following the "call" add a validation to take you to LineLable 10.

The only other option is to post some code for us to make suggestions.

--MiggyD
 
what exactly are you trying to do...?

And, just out of curiosity, why are you using line numbers...

----

you could use a function...

if it returns true then goto 10...

Function Test(bla)
test = 0
...
if something happens then test = not 0
...
everything that is in your normal sub
...
end Function


5 bla
10 bla go here bla
15 bla bla bla
20 if test(x) then goto 10

if this is too confusing let me know, or post some code...

Good Luck

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
I would just take the lines that you want to run after the sub (Line 10) and put it into another sub
 
CubeE101:

Thanks for exemplifying what I've said.


THEMAN101:

Has any of these answers helped? Please let us know.

--MiggyD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top