Line numbers

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
User avatar
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Line numbers

Post by Patz QuickBASIC Creations » Mon Oct 31, 2005 7:29 pm

Is there/can somone help me make/can someone design - a program that puts line numbers INTO the program? I am not very good manipulating programs without the WRITE and INPUT commands. (need for error handler) Any thoughts/suggestions/comments? :P (This would hope QBasic kind! - Anyway, I don't want to put these in all manually(b/c ECLIPSE is too big)

PSUDEO

Code: Select all

'ECLIPSE
DECLARE SUB classified ()
DECLARE SUB evenmoreclassified ()
DECLARE SUB yourejustdyingtoknowarentyou ()
gets turned into:

Code: Select all

1:'ECLIPSE
2:DECLARE SUB classified ()
3:DECLARE SUB evenmoreclassified ()
4:DECLARE SUB yourejustdyingtoknowarentyou ()

User avatar
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations » Mon Oct 31, 2005 7:43 pm

Thanks again, Micro$hit! Of course they design a program to REMOVE line numbers, but not to create! Thanks a bunch :evil:

User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} » Mon Oct 31, 2005 7:59 pm

I have more ideas.

Code: Select all

Get line
ouput str$(current line num) + the old line
That should do it. just get the line, add the line num to the left and re-output the file.
Image

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Mon Oct 31, 2005 8:28 pm

Back before QB, when Microsoft Basic was called GWBASIC, you needed to write your programs with line numbers. The line numbers preceeded each statement and had a space before the code. Example:
100 a = 100
200 for x = 1 to 20

There was a utility program that came with GWBASIC for reassigning (renumbering) the line numbers. I can't remember the name.

Anyway, this utility assumed that that the code already had line numbers. Since your code doesn't have any line numbers to start with, it wouldn't do you any good.

Why do you want to put line numbers in your code?
Do you really want a ":" after the line number?
Do you really want the line numbers to be in increments of 1?

Here's a sample program to do it. OLDPROG.BAS is the filename of the original code that you want to put line numbers into. NEWPROG.BAS is the new code with the inserted line numbers. Yes, I already tested it.

Code: Select all

open "OLDPROG.BAS" for input as #1
open "NEWPROG.BAS" for output as #2
linenum=0
do while not eof(1)
     line input #1, d$
     linenum=linenum+1
     newd$=ltrim$(str$(linenum))+":"+d$
     print #2,newd$
loop
system
Note: The above is not suppressing any leading blanks that your original code lines might have. If you want to suppress these, then where it has "+d$" change to "+ltrim$(d$).
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.

Guest
Veteran
Posts: 128
Joined: Sun Aug 14, 2005 8:33 pm
Location: Forest Lake, MN
Contact:

Post by Guest » Mon Oct 31, 2005 8:36 pm

PQBC wrote:Thanks again, Micro$hit! Of course they design a program to REMOVE line numbers, but not to create! Thanks a bunch :evil:
Christ, its just a company! Get over it...

User avatar
Xerol
Veteran
Posts: 81
Joined: Tue Jan 04, 2005 6:27 pm
Location: Timonium, MD
Contact:

Post by Xerol » Mon Oct 31, 2005 8:46 pm

Actually, GW had a built-in function to renumber lines. I have a GW book right here, I'll look it up:
RENUM Command

Purpose: To renumber program lines.

Syntax: RENUM(new number),(old number)(,increment)

Comments:
-new number is the first line number to be used in the new sequence. The default is 10.

-old number is the line in the current program where renumbering is to begin. The default is the first line of the program.

-increment is the increment to be used in the new sequence. The default is 10.

-RENUM also changes all line number refrences following ELSE, GOTO, GOSUB, THEN, ON..GOTO, ON..GOSUB, RESTORE, RESUME, and ERL statements to reflect the new line numbers.
[...]
So just typing RENUM would renumber the entire program. This was REALLY DAMN USEFUL when you wanted to add stuff in to the program, because even if you were numbering by 10s, eventually you'd run out of space to add lines. The most useful part was the renumbering of line references; I used an awful lot of GOSUBs in my GW days.

Surpressing existing leading whitespace might be a bad idea if you want to preserve code indenting.
If you need music composed in MP3, WAV, or MIDI format, please contact me via email.

Xerol's Music - Updated Regularly!

User avatar
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations » Tue Nov 01, 2005 5:43 pm

moneo to the rescue! Thanks again... :wink:

Post Reply