Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prg to create color variables (screen 0)
#1
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.

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
Reply


Messages In This Thread
Prg to create color variables (screen 0) - by Abazek - 03-03-2025, 01:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Screen fonts in SCREEN 0 BDS107 14 3,579 07-08-2025, 08:05 PM
Last Post: madscijr
  Color Valuenator(tm) by Steve the Awesome(tm)(c) SMcNeill 12 2,645 12-08-2022, 01:28 PM
Last Post: vince
  Directory Create Utility eoredson 6 1,566 09-17-2022, 11:43 AM
Last Post: Kernelpanic
  256 color CMYK and Printstring variants James D Jarvis 0 661 07-13-2022, 07:31 PM
Last Post: James D Jarvis
  CMYK color James D Jarvis 1 842 06-30-2022, 01:24 PM
Last Post: James D Jarvis

Forum Jump:


Users browsing this thread: 1 Guest(s)