Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:58 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : GoSub Help Please

Author Message
Hans

Senior Member

Joined: 18/10/2022
Location: Canada
Posts: 116
Posted: 09:55pm 15 Jun 2023
Copy link to clipboard 
Print this post

Hi all;

What am I missing about the GOSUB command?

I get this weird error "Error : Invalid character:" when I use GOSUB Test, but if I just use the word test and leave out GOSUB, it executes the subroutine correctly????

I have supplied an example in its simplest form.

Details;


The program;


Error;


I don't understand how the GOSUB command is supposed to be used or why it works this way.

TIA

Hans ...
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 10:01pm 15 Jun 2023
Copy link to clipboard 
Print this post

GOSUB doesn't call a SUB.


'My test

GOSUB routine

treaacle

END


routine:
Print "This is a routine called by GOSUB"
RETURN

SUB treacle
print "This is treacle"
END SUB



It's a bit misleading. GOSUB was short for GO SUBROUTINE originally. It's long in the tooth now but still has the occasional use for calling labels.
Edited 2023-06-16 08:03 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6100
Posted: 10:02pm 15 Jun 2023
Copy link to clipboard 
Print this post

GOSUB is the old way of calling subroutines

  Quote  ' my test

test

END

SUB test
PRINT "hello"

END SUB



The manual has a good description of calling SUBs and FUNCTIONs

Jim
VK7JH
MMedit   MMBasic Help
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3804
Posted: 10:33pm 15 Jun 2023
Copy link to clipboard 
Print this post

I think GOSUB would work with a label (or line number) rather than a SUB name.

New programs just don't need GOSUB.

John
 
Hans

Senior Member

Joined: 18/10/2022
Location: Canada
Posts: 116
Posted: 10:44pm 15 Jun 2023
Copy link to clipboard 
Print this post

Thank you Jim and Mick!

IMHO it's not very "basic".

Now all I have to do is cleanup the giant pile of hair next to my desk.

Again thanks;

Hans ...
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 11:21pm 15 Jun 2023
Copy link to clipboard 
Print this post

GOSUB is old school and should generally not be used for new code. It is useful to allow older programs which use it to continue to run.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 339
Posted: 02:28am 16 Jun 2023
Copy link to clipboard 
Print this post

  Hans said  Thank you Jim and Mick!

IMHO it's not very "basic".

Now all I have to do is cleanup the giant pile of hair next to my desk.

Again thanks;

Hans ...


For the first thirty years or so of BASIC's life, programs had to have line numbers. There were no alphanumeric labels. GOSUB nnnn...RETURN (where nnnn is a line number) was the only way to perform a subroutine. There was no CALL...SUB pair. It wasn't until the ANSI X3 committee tried to update BASIC that newer constructs such as DO...LOOP, multiline IF...THEN...ELSE...END IF, FUNCTIONS and SUBs were made a part of the official language.
 
Pilot352
Newbie

Joined: 12/08/2020
Location: United States
Posts: 34
Posted: 11:30am 16 Jun 2023
Copy link to clipboard 
Print this post

** POST REMOVED BY AUTHOR **
Edited 2023-06-16 21:34 by Pilot352
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024