Qbasicnews.com

Full Version: Line Numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
would it be good practise to add numbers to all your lines in a program for thr GOTO statement eg.

Code:
1 PRINT "Hello"
2 INPUT etc.
No. The best thing that MS did to BASIC was to get rid of line numbers.
ComDriver,

That's really upto the individual.
Some people like them, and some don't.
The best advantage to having them is while you're creating the program, they make great reference points.
I like to use: ON ERROR GOTO 5000 'ErrorHandle.
Then at 5000(ErrorHandle) you can have:
Print ERR, ERL:END
This will help to narrow down just exactly where the ERROR (ERL), happened and what the ERROR was (ERR).
Once the program is running smoothly, you may want to run the program "RemLine". This removes all of the unneccessary line numbers, but retains those that are needed for the GOSUB, GOTO,...etc.
This can also be done without using RemLine, but RemLine is much faster.
Once that's done you may want to replace the line numbers with Labels(names), like "5000" with "ErrorHandle" and so on.
Again, It's really upto the individual. :wink:
Or you could simply just use line labels to begin with:
mylabel:

But generally, try to avoid using GOTO, and if you really need it, make it very clear where it goes, and why. That is, if you plan to share the source.
If you're gonna keep the source to yourself, do whatever you want. Heck, use LET if you feel it improves your coding style Big Grin
Some people say, If you use GOTO then there's smth wrong with your code -try to check over, there for certain is another way.

But, in my opinion GOTO can be useful, just don't use it too mutch and try avoiding spagetties with GOTO.
GOTO has it's uses in programming , but FORGET about line numbers. It's the single most stupid thing the original BASIC had...If you modify a program, you must rework your line numbering to keep line numbers ordered and unique. I'm using a Basic where line numbering is mandatory and every change takes double time.
For a reference any good IDE is able to display true line numbers besides the listing without hardwiring them in the program. And if you are using Notepad, just get a good Notepad replacement able to GoTo a line.
if you really feel the need to use linenumbers then, use some big step, like 100, 200, 300, 400, it'll leave you option to add later between more things(101,102,etc), however keep in mind(I may be wrong) that linenumbers in QBasic are 16 unsigned numbers so -nogreater then 64k
Line numbers are just labels.

46486464616186486:

Works, although labels have a maximum char limit.

And really, use text labels

Compare:
Goto 288193
And:
Goto ReDrawCharacters
What's wrong with line numbers? Everything. Imagine that you have to insert a block of code somewhere, or you have to move a block of code elsewhere... You have to manually adjust all the line numbers again.
I think one can see now why I said it's up to the individual.
Labels are used to make programming easier for the programmer, but they are not carried over into the final product. when the program is made into an ".exe" or ".com" format, the labels are dropped and replaced with numbers.
The suggestion of using the 100,200,...etc. approach is a good one.
By the way, there is nothing wrong with using the GOTO statement. It's used in assembly langauge, but in a different form.
There it's called JMP (jump). :bounce:
That too, in my opinion, is up to ones own personal preference. :wink:
Pages: 1 2