03-03-2025, 01:44 AM
I've made a lot of programs that use colored text in Screen 0. My problem is, sometimes I forget which number is which color. So, I create named variables for each color (ie: red, blu, grn, lred, lblu, lgrn, ect). Then I can just type in, for example, COLOR LRED and know it is going to be light red.
The code below creates a file, COLORSUB.BAS , which contains the code to use these variables. That is, a SUB to set the variable values (initTextColors) and a DIM SHARED with the variables themselves. You can then either use COLORSUB.BAS as the start of new program code, or copy/paste from it into an existing program code.
I did this years ago in QBASIC, but couldn't find the original file. So I re-created it back in 2020. Then modified it the other day to work with QB64 / QB64PE.
The file it creates looks like this:
The code below creates a file, COLORSUB.BAS , which contains the code to use these variables. That is, a SUB to set the variable values (initTextColors) and a DIM SHARED with the variables themselves. You can then either use COLORSUB.BAS as the start of new program code, or copy/paste from it into an existing program code.
I did this years ago in QBASIC, but couldn't find the original file. So I re-created it back in 2020. Then modified it the other day to work with QB64 / QB64PE.
Code: (Select All)
'' MakColSb.bas -- Make Color Sub
'' by Abazek, 2020mar03 (updated 2025mar01)
''
'' Creates a text file containing QBasic/QB64/QB64PE code to create shared
'' variables for the standard SCREEN 0 text colors.
''
'' Resulting code contains the SUB (put at end of code with other SUBs), the
'' DIM Shared (put towards start of code with other DIMs/CONSTs/TYPEs), and
'' the DECLARE SUB (which is only needed for QBasic and QuickBasic. QB64 and
'' QB64PE don't require it)
''
'' DATA statement at the end contains color variable names I normally use.
'' You can change them to your liking.
''
DIM ColNam(0 TO 15) AS STRING
DIM q, a$
a$ = "DIM SHARED "
'' Read in Data. Add color name and comma-space to above Dim Shared.
FOR q = 0 TO 15
READ ColNam(q)
a$ = a$ + ColNam(q) + ", "
NEXT q
'' remove the last comma-space
a$ = LEFT$(a$, LEN(a$) - 2)
'' write it out
OPEN "ColorSub.bas" FOR OUTPUT AS #1
PRINT #1, "DECLARE SUB initTextColors ()"
PRINT #1,
PRINT #1, a$
PRINT #1,
PRINT #1, "SUB initTextColors"
FOR q = 0 TO 15
a$ = " " + ColNam(q) + " =" + STR$(q)
PRINT #1, a$
NEXT q
PRINT #1, "END SUB"
CLOSE #1
PRINT
PRINT "New COLORSUB.BAS file has been created."
PRINT
END
DATA blk,blu,grn,cyn,red,pur,brn,lgr,dgr,lblu,lgrn,lcyn,lred,lpur,lyel,wht
The file it creates looks like this:
Code: (Select All)
DECLARE SUB initTextColors ()
DIM SHARED blk, blu, grn, cyn, red, pur, brn, lgr, dgr, lblu, lgrn, lcyn, lred, lpur, lyel, wht
SUB initTextColors
blk = 0
blu = 1
grn = 2
cyn = 3
red = 4
pur = 5
brn = 6
lgr = 7
dgr = 8
lblu = 9
lgrn = 10
lcyn = 11
lred = 12
lpur = 13
lyel = 14
wht = 15
END SUB