Replace Goto

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
johnno56
Newbie
Posts: 3
Joined: Wed Feb 25, 2015 7:36 pm

Replace Goto

Post by johnno56 »

I have a bunch of old basic listings (line numbers) and I am trying to change them to a "more structured" look. (without line numbers)

Are there any tutorials on how to replace "goto" statements? Gosub's I can replace with "sub" routines. But the way most old listings are written, the goto's, are jumping all around the listing causing me no end of confusion. Also, in most cases, the "on goto's" can be a headache. I am not asking anyone to re-write them, otherwise I do not learn as much, I just need to know if there are any tips, tutorials, subroutines, that can be used to replace "goto"

Any information would be greatly appreciated.

J
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: Replace Goto

Post by burger2227 »

GOTO is tough to redo, that's why we don't recommend it anymore to anyone, especially beginners.

Spaghetti code is very hard to fix so use loops instead where you can find them. GOTO is a last resort!

There are programs to get rid of line numbers, except where actually needed that may make it less confusing.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
johnno56
Newbie
Posts: 3
Joined: Wed Feb 25, 2015 7:36 pm

Re: Replace Goto

Post by johnno56 »

I figured that you would respond like that... *sigh* I too find spaghetti code difficult, especially when to goto's jump all over the place, and try use loops and subs and functions where I can. There are a lot of old games and programs that were quite good in their day, and I figured that I could try and resurrect some of them, using current methods. Then the 'goto's' throw a spanner in the works... I was hoping that someone may have developed a method of converting early basic to a more structured basic. I though it might be a bit of a big request, but I figured I would ask anyway.

Looks like I may need a bigger supply of pen and paper and coffee...

Thank you for replying so quickly.

Regards

J
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: Replace Goto

Post by burger2227 »

Use this program to remove unecessary line numbers and it will make your job a lot easier: http://www.qb64.net/wiki/index.php/Line_number

There is also a link to a Microsoft program called remline.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
johnno56
Newbie
Posts: 3
Joined: Wed Feb 25, 2015 7:36 pm

Re: Replace Goto

Post by johnno56 »

Ok. Very cool indeed. That little gem will save heaps of time. Much appreciated.

On a side note:

I have found a published basic listing called 'Haunted House", which is a simple 64 location 'text adventure', that I am trying to convert it using only loops and subs. It has line numbers, but I cannot use your program, as the listing is a pdf. If I get it finished, and I can get it to run, would you be able to give it a "look over" to see where improvements can be made? ( Cool. A conditional If...then statement. )

ps: Do not hold your breath waiting. My skills are not that good...

Regards

J
Post Reply