Page 1 of 1

Line numbers

Posted: Mon Oct 31, 2005 7:29 pm
by Patz QuickBASIC Creations
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 ()

Posted: Mon Oct 31, 2005 7:43 pm
by Patz QuickBASIC Creations
Thanks again, Micro$hit! Of course they design a program to REMOVE line numbers, but not to create! Thanks a bunch :evil:

Posted: Mon Oct 31, 2005 7:59 pm
by {Nathan}
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.

Posted: Mon Oct 31, 2005 8:28 pm
by moneo
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$).
*****

Posted: Mon Oct 31, 2005 8:36 pm
by Guest
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...

Posted: Mon Oct 31, 2005 8:46 pm
by Xerol
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.

Posted: Tue Nov 01, 2005 5:43 pm
by Patz QuickBASIC Creations
moneo to the rescue! Thanks again... :wink: