|
Post by grexie on May 18, 2021 9:18:42 GMT
Hi, is it possible to use line numbers in the source code of Just Basic? I want to run the program in GW Basic 3.2, too. It's only retro fun. Regards ... Grexie
|
|
|
Post by Rod on May 18, 2021 11:15:18 GMT
Yes you can have line numbers. Best to post the code if you want help. Just BASIC treats the line numbers as [Branch label] So you can identify the important line numbers and replace them with meaningful branch names. Best to start with short bits of code till you get the idea.
|
|
|
Post by tenochtitlanuk on May 18, 2021 15:52:23 GMT
Yup, in JB we generally only label lines which are jumped to ( regarded as bad programming practice!) or to make the code self-documenting, ie make what is happening more obvious. We use ' rather than REM or rem- it looks neater! GWB
' 10 SCREEN 1 ' 20 REM ***** across the top ' 30 LINE (0,0) - (319,0) ' 40 REM ***** down the left side ' 50 LINE (0,0) - (0,199) ' 60 REM ***** across the bottom ' 70 LINE (0,199) - (319,199) ' 80 REM ***** down the right side ' 90 LINE (319,0) - (319,199) '110 REM ***** top left to bottom right '120 LINE (0,0) - (319,199) '130 REM ***** bottom left to top right '140 LINE (0,199) - (319,0)
. . . could in JB be
10 WindowWidth =420: WindowHeight =260 20 open "Graphics Window" for graphics_nsb as #wg 30 #wg "goto 2 2 ; down ; goto 402 2 ; up" 40 REM ***** down the left side 50 #wg "goto 2 2 ; down ; goto 2 202 ; up" 60 REM ***** across the bottom 70 #wg "goto 2 202 ; down ; goto 402 202 ; up" 80 REM ***** down the right side 90 #wg "goto 402 202 ; down ; goto 402 2 ; up" 110 REM ***** top left to bottom right 120 #wg "goto 2 2 ; down ; goto 402 202 ; up" 130 REM ***** bottom left to top right 140 #wg "goto 2 202 ; down ; goto 402 2 ; up" 150 wait
But we'd probably write it more like
WindowWidth =420: WindowHeight =250 ' specify graphic window size
nomainwin ' don't show main ( console) window
open "Graphics Window" for graphics_nsb as #wg ' create the window
#wg "trapclose quit" ' specify what to do if 'close' icon clicked
#wg "fill cyan" ' fill background in cyan P =int( 256 *rnd( 1)) #wg "color "; P; " 80 "; 255 -P ' choose a random line RGB spec'n #wg "size "; int( 1 +7 *rnd( 1)) ' and its width
#wg "goto 2 2 ; down ; goto 402 2 ; up" #wg "goto 2 2 ; down ; goto 2 202 ; up" #wg "goto 2 202 ; down ; goto 402 202 ; up" #wg "goto 402 202 ; down ; goto 402 2 ; up" #wg "goto 2 2 ; down ; goto 402 202 ; up" #wg "goto 2 202 ; down ; goto 402 2 ; up" wait
sub quit h$ ' specify what to do if 'close' cliched close #h$ ' close window and end. end end sub
Go for it! It's a VERY easy and powerful BASIC and a great helpful community.
|
|
carlg
New Member
Posts: 14
|
Post by carlg on May 18, 2021 19:44:02 GMT
Hi, is it possible to use line numbers in the source code of Just Basic? I want to run the program in GW Basic 3.2, too. It's only retro fun. Regards ... Grexie Yeah, you can use line numbers. You will need to save your GW-BASIC program with an A switch so that it is an ASCII file, like so: SAVE "MYPROG.BAS", A Check out this video where I show how to adapt a line numbered BASIC program to Liberty BASIC/Just BASIC. youtu.be/lJnIoHuDbic
|
|
|
Post by grexie on May 20, 2021 12:23:45 GMT
Thanks for your help! That's great that I can use line numbers in my JB source code. Then I want to know: Is it possible to include line numbers automatically? Does JB have a built-in function to create line numbers after finishing the source code?
|
|
|
Post by Rod on May 20, 2021 18:05:50 GMT
The native editor does not support such line numbering but other editors do. Line numbers are a bit old hat and you will find that you will leave them behind very quickly. Alyce has a freware editor that supports line numbering, alycesrestaurant.com/workshop.htmNot sure if the line numbering will port to GW-BASIC without a few tweaks, you will need to experiment.
|
|
|
Post by toughdiamond on May 26, 2021 21:21:57 GMT
Check out this video where I show how to adapt a line numbered BASIC program to Liberty BASIC/Just BASIC. youtu.be/lJnIoHuDbicSome good tips there. I suppose the line numbers could be automatically removed using something like a$=mid$(a$,6), as long as the line numbers after GOTO statements etc. had already been dealt with. Has anybody created a JB program to do the whole thing automatically? Seems to me that would be the most labour-intensive part of the process, though I see it would still need quite a bit of user input to decide on good alpha names where they were required. I remember Sinclair BASIC was indeed quite non-standard in places, GWBasic less so. I was surprised how easy it was to get some of my old GWBasic programs running in JB. And it's so much better to have tons more available RAM and freedom from those cumbersome mandatory line numbers, and not to be stuck with old 8-character DOS file and directory names. I was limping on with GWBasic as my only language until I discovered JB early this year.
|
|
|
Post by tsh73 on May 27, 2021 5:40:00 GMT
Microsoft created remlines.bas It strips all line numbers except ones used in GOTO
Google around.
|
|
|
Post by toughdiamond on May 27, 2021 13:56:58 GMT
|
|
|
Post by Rod on May 27, 2021 18:03:43 GMT
Line numbers are just one aspect of converting .bas files. Usually there are screen types and data types and other quirks to resolve. Working through gives you a much better understanding of the program.
|
|
|
Post by tsh73 on May 27, 2021 20:32:24 GMT
Really interesting. I always took having QBASIC available for granted, so I never thought (or cared) of REMLINE be uncompatible with JB.
No, that's not original program. Original program called REMLINE.BAS, my copy size 12 318 bytes, 398 lines Starts with LOOONG comment (41 lines!)
' ' Microsoft RemLine - Line Number Removal Utility ' Copyright (C) Microsoft Corporation 1985-1990 ' ' REMLINE.BAS is a program to remove line numbers from Microsoft Basic ' Programs. It removes only those line numbers that are not the object ' of one of the following statements: GOSUB, RETURN, GOTO, THEN, ELSE, ' RESUME, RESTORE, or RUN. '
And indeed it needs some heavy adapting to JB I pretty sure someone already did that - but I apparently do not have it.
Code from your link is much smaller, 92 lines, 3064 bytes. Under the code attribution is written
Since it smaller, I quite fast made it run under JB While testing, I found one problem with it: it does not supports things like
ON ME(J) GOSUB 770,720,640 - so on this case, it preserved first number (770) but deleted other two. Anyway JB does not support this construction either, so if you encounter this, you will have to rewrite it somehow.
Here it is Since it attempts to rewrite source program, having backup is a wise move.
'from 'http://www.qb64.net/wiki/index-php/Line_number/ ' Code courtesy of Pete from the Network 54 Qbasic Forum 'adaptation to JB by tsh73, may 2021 CLS REDIM linenumber(100000) PRINT "This Program removes unnecessary line numbers.": PRINT INPUT "Name of file: "; filename$: PRINT OPEN filename$ FOR INPUT AS #1 DO UNTIL EOF(#1) LINE INPUT #1, a$ REM Get rid of quotes and REM statements. DO while 1 IF INSTR(a$, CHR$(34)) <> 0 THEN IF INSTR(a$, CHR$(34), INSTR(a$, CHR$(34)) + 1 ) = 0 THEN EXIT DO: REM Mismatched quotes. Illegal code. a$ = MID$(a$, 1, INSTR(a$, CHR$(34)) - 1) + MID$(a$, INSTR(a$, CHR$(34), INSTR(a$, CHR$(34)) + 1) + 1) ELSE EXIT DO END IF LOOP IF INSTR( upper$(a$), "REM ") <> 0 THEN a$ = MID$(a$, 1, INSTR( upper$(a$), "REM ")) IF INSTR( upper$(a$), "' ") <> 0 THEN a$ = MID$(a$, 1, INSTR(a$, "' ")) DO while 1 flag = 0 REM Break down compound statements and get line numbers. IF INSTR(a$, "GOTO ") <> 0 THEN flag = 1: n = INSTR(a$, "GOTO ") + 5: GOSUB [tracknumber] IF INSTR(a$, "GOSUB ") <> 0 THEN flag = 1: n = INSTR(a$, "GOSUB ") + 6: GOSUB [tracknumber] IF INSTR(a$, "THEN ") <> 0 THEN flag = 1: n = INSTR(a$, "THEN ") + 5: GOSUB [tracknumber] IF INSTR(a$, "ELSE ") <> 0 THEN flag = 1: n = INSTR(a$, "ELSE ") + 5: GOSUB [tracknumber] IF INSTR(a$, "RUN ") <> 0 THEN flag = 1: n = INSTR(a$, "RUN ") + 4: GOSUB [tracknumber] IF INSTR(a$, "RESUME ") <> 0 THEN flag = 1: n = INSTR(a$, "RESUME ") + 7: GOSUB [tracknumber] IF INSTR(a$, "RETURN ") <> 0 THEN flag = 1: n = INSTR(a$, "RETURN ") + 7: GOSUB [tracknumber] IF flag = 0 THEN EXIT DO ELSE a$ = MID$(a$, n) LOOP LOOP PRINT "Number of line-numbered statements kept:"; count CLOSE #1 OPEN filename$ FOR INPUT AS #1 OPEN "filename.tmp" FOR OUTPUT AS #2 DO UNTIL EOF(#1) LINE INPUT #1, a$ flag = 0 IF VAL(MID$(a$, 1, 1)) <> 0 THEN FOR i = 1 TO count IF VAL(a$) = linenumber(i) THEN flag = 1: EXIT FOR NEXT IF flag = 0 THEN a$ = MID$(a$, INSTR(a$, " ") + 1) END IF PRINT #2, a$ LOOP CLOSE #1 CLOSE #2 run "notepad.exe filename.tmp" PRINT PRINT "Back up original file as .org and give edited file original file name? [Y/N]" DO while 1 'b$ = upper$(INKEY$) b$ = upper$(input$(1)) SELECT CASE b$ 'CASE CHR$(27): SYSTEM 'does not provide ESC CASE "N" 'ON ERROR GOTO [resnxt] 'KILL "filename.tmp" 'ON ERROR GOTO 0 call tryKill "filename.tmp" PRINT PRINT "Temporary "+ CHR$(34) + "filename.tmp" + CHR$(34) + " was removed and no changes were made to original file." PRINT PRINT "Press any key to end." EXIT DO CASE "Y" 'ON ERROR GOTO [resnxt] 'KILL MID$(filename$, 1, INSTR(filename$, ".") - 1) + ".org" 'ON ERROR GOTO 0 call tryKill MID$(filename$, 1, INSTR(filename$, ".") - 1) + ".org" NAME filename$ AS MID$(filename$, 1, INSTR(filename$, ".") - 1) + ".org" NAME "filename.tmp" AS filename$ PRINT : PRINT "File conversion completed. Press any key to end." EXIT DO END SELECT LOOP 'SLEEP 'SYSTEM end
[tracknumber] DO while 1 count = count + 1 linenumber(count) = VAL(MID$(a$, n)) IF INSTR(a$, "ON") <> 0 AND INSTR(a$, "GOSUB") <> 0 OR INSTR(a$, "ON") <> 0 AND INSTR(a$, "GOTO") <> 0 THEN FOR i = n TO LEN(a$) IF VAL(MID$(a$, i, 1)) = 0 AND MID$(a$, i, 1) <> "0" AND MID$(a$, i, 1) <> "," AND MID$(a$, i, 1) <> " " THEN EXIT FOR IF MID$(a$, i, 2) = ", " THEN n = i + 1: EXIT FOR NEXT IF n <> i + 1 THEN EXIT DO ELSE EXIT DO END IF LOOP RETURN '[resnxt] 'RESUME NEXT
sub tryKill fileName$ on error goto [err] kill fileName$ exit sub [err] print "ERR: failed to kill a file ";fileName$ end sub
|
|
|
Post by toughdiamond on May 28, 2021 0:10:20 GMT
Line numbers are just one aspect of converting .bas files. Usually there are screen types and data types and other quirks to resolve. Working through gives you a much better understanding of the program. Indeed. Removing line numbers automatically will / would be helpful if the program does the job well, but it would be very lucky indeed if that was all that was needed. Really interesting. I always took having QBASIC available for granted, so I never thought (or cared) of REMLINE be uncompatible with JB. I tried it some years ago but couldn't get it to do much. Don't know if that was a problem with the installation or just me being a slow learner. At the time I couldn't find anything that didn't present a plethora of problems, so I gave up and reluctantly continued with GWBasic, which in spite of its many inadequacies, I was very accustomed to. Eventually I wanted to start a project that I knew it wasn't up to, so without much hope I took another look, found JB, and was astonished how easy the transition was. Thanks, that helped me to find the original program. I was getting nowhere with the Pete-modified one, which kept giving errors, and if it's down to something being wrong with my version of QBasic, I suspect the original program won't work here either. But your translation of the Pete-modified program into JB will at least get round that. Luckily I'm sure all the GOSUBs I've ever written have been just to one line number - I never used a lot of the "advanced" features, but the fact that such things can happen means the program will need to be used with caution. Though I never knew Microsoft's RENUMBER command to screw anything up, and that would have to take all such things into account, so I've a feeling the original REMLINE.BAS might be flawless if I can get it to run at all.
|
|
|
Post by tsh73 on May 28, 2021 8:40:17 GMT
It's not QBASIC code
REDIM linenumber(100000) surely too big for QBASIC
|
|
|
Post by toughdiamond on May 28, 2021 14:11:37 GMT
It's not QBASIC code REDIM linenumber(100000) surely too big for QBASIC Aha! Turns out it's for QB64, a modernised version of Qbasic, which looks a lot less of a pain in the butt than old Qbasic. github.com/QB64Team/qb64/releases/tag/v1.5Misleadingly, the error that stopped Qbasic from running it wasn't the REDIM command, it was SHELL PRINT which doesn't even appear in the actual program. No wonder I was confused. The compiler, being the wrong one, must have altered a few things. Anyway, back on track now, your JB-adapted code works here, not surprisingly. Hurdles to understanding how it works (in my case) include the commands REDIM, UNTIL, SELECT CASE, SLEEP, and DO loops (which I haven't seen since the 1970s, in FORTRAN I think - all this time I'd been hoping they'd been discontinued in favour of FOR-NEXT loops).
|
|
|
Post by toughdiamond on May 29, 2021 21:20:34 GMT
OK, just for the record, QB64 does appear to handle the original Microsoft line-removing program without screwing it up. Original BASIC program is here: www.qb64.org/forum/index.php?topic=2788.0QB64 is here: github.com/QB64Team/qb64/releases/tag/v1.5The line remover worked when I tested it, though my old GwBASIC programs are pretty simple so it wasn't a very rigorous test. I did notice that it wouldn't respond right to my choosing the option not to write the new file to disk, but that scarcely matters. That QB64 package is a biggie - over 500MB unpacked. Don't know what's so wonderful about it that would justify that size. Another odd thing was that instead of running the BASIC program I loaded, it compiled it into an executable. I could be wrong, but I don't think I told it to do that. No worries - the executable works, and it means I don't have to use QB every time I want to remove lines from a GwBASIC program, which suits me because in my hands QBASIC is an awkward cuss at the best of times. I'd share the executable but I don't know if it's permissible / desirable / technically possible. It's 1.64mb so it exceeds the attachment size limit, and a lot of people are rightly wary of strangers bearing executable gifts.
|
|