My Nostalgia; codes for the old BASIC product family (GW-BASIC, QuickBASIC and so on) before Visual Basic
- Decimal/Hexadecimal Convertor (2023.12.10)
- Line Numbering 2 (2023.07.22)
- Line Numbering (2023.07.19)
- Draw A Car (2022.02.09)
- Play Music (2021.02.20)
- Hello World (2020.02.27)
- References (2020.02.25)
-
To practice Subroutine with
GOSUB
~RETURN
statements- Reference : 8비트 컴퓨터에서 게임 만들기 (YouTube)
-
Be aware of BOM(Byte-Order Mark;
EF BB BF
) signature generation when creating a code file with an external editorCodes : HEXCONV.BAS
0 CLS 10 PRINT "*************************************" 20 PRINT "* <Decimal/Hexadecimal Convertor> *" 30 PRINT "* kimpro82 / 2023.12.10, not 1993 *" 40 PRINT "* * * * * * * * * * * * * * * * * * *" 50 PRINT "* 1. Convert Decimal to Hexadecimal *" 60 PRINT "* 2. Convert Hexadecimal to Decimal *" 70 PRINT "* 3. Exit *" 80 PRINT "*************************************" 90 INPUT " Select a menu (1, 2, 3): "; MENU 100 IF MENU = 1 THEN GOSUB 200 110 IF MENU = 2 THEN GOSUB 300 120 IF MENU = 3 THEN END 130 GOTO 90 200 ' Subroutine for Decimal to Hexadecimal Conversion 210 INPUT " Enter a decimal value: "; DEC 220 PRINT " Hexadecimal value : "; HEX$(DEC) 230 RETURN 300 ' Subroutine for Hexadecimal to Decimal Conversion 310 INPUT " Enter a hexadecimal value: "; HEXA$ 315 ' The keyword HEX$(X) is already in use 320 PRINT " Decimal value : "; VAL("&H" + HEXA$) 330 RETURN
-
Finally I've got GW-BASIC 3.23!
-
Reversed line numbers are automatically rearranged as increasing order
-
Line numbers are allowed only when they are not exceeding
65529
and without decimal points.Why `65529`, not `65535`?
-
Variances in Basic highest line numbers (retrocomputing.stackexchange.com)
Line numbers are stored as a two byte word but the largest allowed by the input routines is 65529. Primarily because this is an easier limit to test rather than checking for overflow. The line number is converted from ASCII to binary a character at a time using a pretty standard algorithm. Start with a 16 bit value
line
= 0. For each digit multiplyline
by 10 and add the digit toline
.To check if the line number is acceptable, compare
line
against 6552 before multiplying it by 10. This will guarantee the value is <= 65529 because a digit can add only 9 at most.
What does `!` mean?
-
Microsoft > Learn > Documentation > .NET > Visual Basic > Single Data Type
This is not exactly GW-BASIC, but it is a descendant with some traces of its syntax.
Type Characters. Appending the literal type character
F
to a literal forces it to theSingle
data type. Appending the identifier type character!
to any identifier forces it toSingle
.
Codes : LINENUM2.BAS
- Saved in the file
10 PRINT 10 20 PRINT 20 30 GOTO 50 40 PRINT 40 ' Pass 50 PRINT 50 60 PRINT 60 55 PRINT 55 ' Rearranged as increasing order 70.5 PRINT 70.5 ' Syntax rrror; 70 .5 PRINT 70.5 65530 PRINT 65530 ' Syntax rrror; 6553 0 PRINT 65530! 65529 PRINT 65529 ' 65529! 65531 PRINT 65531 ' Syntax rrror
- Loaded on the GW-BASIC console
10 PRINT 10 20 PRINT 20 30 GOTO 50 40 PRINT 40 ' Pass 50 PRINT 50 55 PRINT 55 ' Rearranged as increasing order 60 PRINT 60 70 .5 PRINT 70.5 ' Syntax rrror; 70 .5 PRINT 70.5 6553 0 PRINT 65530! ' Syntax rrror; 6553 0 PRINT 65530! 65529 PRINT 65529! ' 65529! Syntax error
- Output
RUN 10 20 50 55 60 Syntax error in 70 Ok
-
-
I intended to write GW-BASIC code, but I actually executed it in QuickBASIC.
-
Unexpectedly, many things are allowed, including aspects that were not even considered.
Ex) Line numbers including decimal points, reversed, or exceeding 65535 ……Codes : LineNum.bas
'-10 print "-10" ' A negative line number causes an error 0 CLS 10 PRINT "10" 15 GOTO 30 20 PRINT "20" ' Pass 30 PRINT "30" 25 PRINT "25" ' Decreasing numbering is OK 30.5 PRINT "30.5" ' Decimal point is allowed A: GOTO C B: PRINT "B" C: PRINT "C" ' Alphanumeric line labels can be mixed PRINT "No label" ' Lines without labeling is also available 65535 PRINT "65535" 65536 PRINT "65536" ' The line number can be over 65536
10 30 25 30.5 C No label 65535 65536
-
References
- The BASIC Program Line from QUICKBASIC 4.5 Help file
- Q73084: Differences Between GW-BASIC and QBasic
-
Remember how I felt when I was a primary school student
Codes : DrawCar.bas
CLS SCREEN 12 '640 x 480 / 16 colors wid% = 640 'Can I get these parameters automatically? hei% = 480 'Border LINE (10, 10)-(wid% - 10, 10), 15, B LINE (10, hei% - 80)-(wid% - 10, hei% - 80), 15, B LINE (10, 10)-(10, hei% - 80), 15, B LINE (wid% - 10, 10)-(wid% - 10, hei% - 80), 15, B 'Memo LOCATE 3, 5 PRINT "QuickBasic : My Nostalgia" LOCATE 3, 67 PRINT "2022.02.09" 'Body LINE (wid% / 2 - 100, hei% / 2 - 100)-(wid% / 2 + 100, hei% / 2), 7, BF LINE (wid% / 2 - 200, hei% / 2)-(wid% / 2 + 200, hei% / 2 + 100), 7, BF 'Windows LINE (wid% / 2 - 100, hei% / 2 - 80)-(wid% / 2 - 60, hei% / 2), 9, BF LINE (wid% / 2 - 50, hei% / 2 - 80)-(wid% / 2 - 5, hei% / 2), 9, BF LINE (wid% / 2 + 5, hei% / 2 - 80)-(wid% / 2 + 50, hei% / 2), 9, BF LINE (wid% / 2 + 60, hei% / 2 - 80)-(wid% / 2 + 100, hei% / 2), 9, BF 'Wheels CIRCLE (wid% / 2 - 90, hei% / 2 + 100), 50, 8 CIRCLE (wid% / 2 + 90, hei% / 2 + 100), 50, 8 PAINT (wid% / 2 - 120, hei% / 2 + 100), 8, 8 PAINT (wid% / 2 + 120, hei% / 2 + 100), 8, 8 CIRCLE (wid% / 2 - 90, hei% / 2 + 100), 30, 7 CIRCLE (wid% / 2 + 90, hei% / 2 + 100), 30, 7 PAINT (wid% / 2 - 90, hei% / 2 + 100), 7, 7 PAINT (wid% / 2 + 90, hei% / 2 + 100), 7, 7 END
-
Practice of functions :
BEEP
SOUND
PLAY
-
Run by MS QuickBASIC 4.5
Codes : Xerxes.bas
- Using
SHELL
function to borrow theCLS
command from DOS
SHELL "CLS" PRINT "I am generous"
I am generous
Codes : Sound.bas
- Refer to ☞ https://en.wikibooks.org/wiki/QBasic/Sound
SHELL "CLS" 'BEEP PRINT "BEEP" BEEP PRINT CHR$(7) SLEEP 'SOUND PRINT "SOUND" + CHR$(13) 'CHR$(13) : Line break FOR i% = 1 TO 30 SOUND i% * 100, 1 'Frequency, Duration NEXT SLEEP 'PLAY PRINT "PLAY" + CHR$(13) PLAY "L16 CDEFGAB>C" '> : Move up one octave SLEEP
Codes : SchoolBell.bas
- Play the same song with the keys of both C major and C minor
SHELL "CLS" PRINT "School Bell" PRINT "C major" PLAY "MS G8G8A8A8 G8G8E4 G8G8E8E8 D6 P8" PLAY "MS G8G8A8A8 G8G8E4 G8E8D8E8 C6 P8" PRINT "C minor" PLAY "MS G8G8A-8A-8 G8G8E-4 G8G8E-8E-8 D6 P8" PLAY "MS G8G8A-8A-8 G8G8E-4 G8E-8D8E-8 C6 P8"
- Using
-
PRINT
, notprint
Codes : HelloWorld.bas
print "Hello World!"
Call to undefined sub 'print'
print("Hello World!")
Call to undefined sub 'print'
print 'Hello World!'
Call to undefined sub 'print'
How can I make
print
work?PRINT "Hello World!"
Hello World!
The secret was UPPER CASE!
PRINT 'Hello World!'
''
seems to be used for single-line comments.'You can't see what I'm saying.'
ㅋ
Links
- BASIC
- BASIC (Wikipedia)
https://en.wikipedia.org/wiki/BASIC
- BASIC (Wikipedia)
- QuickBASIC
- QuickBASIC (Wikipedia)
https://en.wikipedia.org/wiki/QBasic
- QuickBASIC (Wikipedia)
- QBasic
- Online IDE for QBasic
https://repl.it/ - QBasic/Full Book View (Wikibooks)
https://en.wikibooks.org/wiki/QBasic/Full_Book_View - Programmed Lessons in QBasic (Central Connecticut State University)
https://chortle.ccsu.edu/QBasic/ - QBasic Tutorials and Articles (QBasic Cafe)
https://www.qbasic.net/en/qbasic-articles/
- Online IDE for QBasic
- QB64
- QBasic / QB64 Tutorial List (SchoolFreeware)
https://www.schoolfreeware.com/QBasic_Tutorials_-_QB64_Tutorials_-_Programming_And_Code_Examples.html
- QBasic / QB64 Tutorial List (SchoolFreeware)