• Please review our updated Terms and Rules here

GOSUB

jjzcp

Experienced Member
Joined
Sep 14, 2005
Messages
123
Location
on the bald a$$ prarie
Hi, why is it, in my BASIC book, when i looked up the gosub command it whent like this........

BOOK

10 print "1"
20 print "2"
30 gosub 80
40 print "3"
50 print "4"
60 gosub 80
70 stop
80 print "5"
90 return
run
1
2
5
3
4

and theTandy 1000 goes like this......

10 print "1"
20 print "2"
30 gosub 40: print "3": end
40 print "4"
50 print "5": return
run
1
2
4
5
3
 
Re: GOSUB

jjzcp said:
Hi, why is it, in my BASIC book, when i looked up the gosub command it whent like this........

BOOK

10 print "1"
20 print "2"
30 gosub 80
40 print "3"
50 print "4"
60 gosub 80
70 stop
80 print "5"
90 return
run
1
2
5
3
4

and theTandy 1000 goes like this......

10 print "1"
20 print "2"
30 gosub 40: print "3": end
40 print "4"
50 print "5": return
run
1
2
4
5
3


I'm not much of a BASIC programmer, but I'll give it a shot, since I don't have a real life either...

Some of your older BASIC dialects didn't support more than one command on a single line, but the T1K running GW-BASIC does, provided the commands are separated with colons. When you give the gosub command, it immediatly jumps to the target line and executes the subroutine there, command-by-command, then line-by-line, until it encounters the RETURN command, at which point, it jumps back to the origin, then executes any other commands found on that line before moving on to the next line.
In the T1K example you've given, the subroutine starts on line 40, then executes the first command on line 50, then the second command on that same line, which is the RETURN command, where it jumps back to line 30 and continues to execute the other command on that line. In other words, your program is doing exactly what you told it to do.

Hope all that makes sense to you, I'm even less of a technical writer than I am a programmer.

--T
 
So.... can i make my tandy run the gosub command just like it did in the book, because when making windows made out of the * sign and having a command promped only half the window loads, then the comand promped appears and once i type something, in the window finishes loading. In order to fix that problem i need this gosub command to work like it does in the book.
 
Yes, AFAIK, the program in the book should work on thr Tandy just the same as it does in the book. It's the multiple commands on a single line that are optional, and they seem to be giving you trouble. Just look at the listing, and follow the program flow, and you'll see just what it is doing, and why.

--T
 
Maybe the Tandy has some kind of buffered output, so it would only print a certain amount of data onto screen before user input? Similar to some computers would prevent scrolling before the user accepted. It may be possible to turn off in that case.
 
Lemme get this straight, you're trying to print a menu on the screen that is framed within a box defined by * characters? How are you displaying the asterisks? Are you using a series of commands that looks like this?
Code:
10 print"***********************************************"
20 print"*                                             *"
30 print"*                                             *"
40 print"***********************************************"

If that's the way you're doing it, you're probably using up all of your default string space. Most BASICs (including GW) allow you to reserve more memory to store string data, usually with a CLEAR command at the beginning of your code, like this:

10 CLEAR 200,10

...or something similar (the exact syntax and parameters you feed in will vary from one BASIC to another)

--T
 
Yes, Alien mentions that use, but I didn't think it related to static strings that are not assigned to a variable. Some Basics (Microsoft 5.0 / Basic-80 and also Sinclair Basic surprisingly) use CLEAR to reserve space for machine code programs on top of variable space.
 
Ok, what about the strings being too long? IIRC, in GW strings may be a maximum of 255 characters in length. Of course, if that were the case, GW would return an error message, wouldn't it?

--T
 
About the window program, no it is not made by using the print command, it was made with the for next, gosub, and if then commands so inputing statements would be less difficult.
:whaasup:
 
Um.. you're not doing anything like this?

10 Y=1:GOSUB 50:FOR Y=2 TO 4:GOSUB 55:NEXT Y
20 PRINT AT 3,4:INPUT "COMMAND";A$
25 FOR Y=5 TO 6:GOSUB 55:NEXT Y:Y=7:GOSUB 50
...
50 REM DRAW ONE HORIZONTAL LINE
51 FOR X=1 TO 20:GOSUB 100:NEXT X:RETURN
55 REM PLOT ONE DOT IN EACH END OF LINE
56 X=1:GOSUB 100:X=20:GOSUB 100:RETURN
...
100 PRINT AT X,Y;"*":RETURN

Given that it would execute at all, it would draw the upper half of the window, then wait for the input and continue with the execution afterwards. Instead you would have to draw the whole window in a whole and insert the command prompt afterwards, but as you're working on an all-purpose GUI, I suppose you separated the GUI from the actual functions.
 
Back
Top