Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3458864
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:02:12+00:00 2026-05-18T10:02:12+00:00

I just finished my a Batch COLOR script that accepts Color-names, Decimals and Hex

  • 0

I just finished my a Batch COLOR script that accepts Color-names, Decimals and Hex Parameters.

This script works exactly like the MS-Color command but it also accepts
decimals and color-names.

Run this script without perimeters for a full description including syntax and usage.

I am wondering if I did a good job or is there something that can be improved?

if    "%_TPfore%"=="A" set "_ValidF=TRUE" && goto TWOPAR_VALID

@echo off
setlocal EnableDelayedExpansion

if "%1"=="/?" goto HELP
if "%1"==""   goto HELP

goto BYPASSREMSTATEMENTS
rem ***********************************************************
rem * Easycolor was created by Edoctoor 2010                  *
rem * With the help from the good people at stackoverflow.com *
rem * For the good people at stackoverflow.com                *
rem *                                                         *
rem * Convert Color-name and Decimals Parmeters to Hex values *
rem * then pass the VALUES to the COLOR COMMAND               *
rem ***********************************************************
:BYPASSREMSTATEMENTS

set "_DEBUGGING=FALSE"
If "%_DEBUGGING%"=="TRUE" prompt=$g && echo on && cls

REM IF TWO PARMETERS GIVEN
IF NOT "%2"=="" call :TWOPAR %1 %2

REM IF ONE PARMETER GIVEN
set _OPback=%1
call :TWOPAR %_OPback:~0,1% %_OPback:~1,1%

goto :eof

rem ***********************************************************
rem * Convert Color-name and Decimals Parmeters to Hex values *
rem * then pass the VALUES to the COLOR COMMAND               *
rem ***********************************************************

:TWOPAR
set "_TPback=%1"
set "_TPfore=%2"
set "_ValidB=FALSE"
set "_ValidF=FALSE"

FOR /L %%B IN (1,1,9) DO (
    if "%_TPback%"=="%%B"                             set "_ValidB=TRUE" && goto TWOPAR_FORE
)

if /I "%_TPback%"=="Black"        set /A _TPback=0 && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="Blue"         set /A _TPback=1 && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="Green"        set /A _TPback=2 && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="Aqua"         set /A _TPback=3 && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="Red"          set /A _TPback=4 && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="Purple"       set /A _TPback=5 && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="Yellow"       set /A _TPback=6 && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="White"        set /A _TPback=7 && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="Gray"         set /A _TPback=8 && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="LightBlue"    set /A _TPback=9 && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="LightGreen"   set    _TPback=A && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="LightAqua"    set    _TPback=B && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="LightRed"     set    _TPback=C && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="LightPurple"  set    _TPback=D && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="LightYellow"  set    _TPback=E && set "_ValidB=TRUE" && goto TWOPAR_FORE
if /I "%_TPback%"=="BrightWhite"  set    _TPback=F && set "_ValidB=TRUE" && goto TWOPAR_FORE
if    "%_TPback%"=="A"                                set "_ValidB=TRUE" && goto TWOPAR_FORE
if    "%_TPback%"=="B"                                set "_ValidB=TRUE" && goto TWOPAR_FORE
if    "%_TPback%"=="C"                                set "_ValidB=TRUE" && goto TWOPAR_FORE
if    "%_TPback%"=="D"                                set "_ValidB=TRUE" && goto TWOPAR_FORE
if    "%_TPback%"=="E"                                set "_ValidB=TRUE" && goto TWOPAR_FORE
if    "%_TPback%"=="F"                                set "_ValidB=TRUE" && goto TWOPAR_FORE
if    "%_TPback%"=="a"                                set "_ValidB=TRUE" && goto TWOPAR_FORE
if    "%_TPback%"=="b"                                set "_ValidB=TRUE" && goto TWOPAR_FORE
if    "%_TPback%"=="c"                                set "_ValidB=TRUE" && goto TWOPAR_FORE
if    "%_TPback%"=="d"                                set "_ValidB=TRUE" && goto TWOPAR_FORE
if    "%_TPback%"=="e"                                set "_ValidB=TRUE" && goto TWOPAR_FORE
if    "%_TPback%"=="f"                                set "_ValidB=TRUE" && goto TWOPAR_FORE

:TWOPAR_FORE

FOR /L %%B IN (1,1,9) DO (
    if "%_TPfore%"=="%%B"                             set "_ValidF=TRUE" && goto TWOPAR_VALID
)

if /I "%_TPfore%"=="Black"        set /A _TPfore=0 && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="Blue"         set /A _TPfore=1 && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="Green"        set /A _TPfore=2 && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="Aqua"         set /A _TPfore=3 && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="Red"          set /A _TPfore=4 && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="Purple"       set /A _TPfore=5 && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="Yellow"       set /A _TPfore=6 && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="White"        set /A _TPfore=7 && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="Gray"         set /A _TPfore=8 && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="LightBlue"    set /A _TPfore=9 && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="LightGreen"   set    _TPfore=A && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="LightAqua"    set    _TPfore=B && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="LightRed"     set    _TPfore=C && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="LightPurple"  set    _TPfore=D && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="LightYellow"  set    _TPfore=E && set "_ValidF=TRUE" && goto TWOPAR_VALID
if /I "%_TPfore%"=="BrightWhite"  set    _TPfore=F && set "_ValidF=TRUE" && goto TWOPAR_VALID
if    "%_TPfore%"=="A"                                set "_ValidF=TRUE" && goto TWOPAR_VALID
if    "%_TPfore%"=="B"                                set "_ValidF=TRUE" && goto TWOPAR_VALID
if    "%_TPfore%"=="C"                                set "_ValidF=TRUE" && goto TWOPAR_VALID
if    "%_TPfore%"=="D"                                set "_ValidF=TRUE" && goto TWOPAR_VALID
if    "%_TPfore%"=="E"                                set "_ValidF=TRUE" && goto TWOPAR_VALID
if    "%_TPfore%"=="F"                                set "_ValidF=TRUE" && goto TWOPAR_VALID
if    "%_TPfore%"=="a"                                set "_ValidF=TRUE" && goto TWOPAR_VALID
if    "%_TPfore%"=="b"                                set "_ValidF=TRUE" && goto TWOPAR_VALID
if    "%_TPfore%"=="c"                                set "_ValidF=TRUE" && goto TWOPAR_VALID
if    "%_TPfore%"=="d"                                set "_ValidF=TRUE" && goto TWOPAR_VALID
if    "%_TPfore%"=="e"                                set "_ValidF=TRUE" && goto TWOPAR_VALID
if    "%_TPfore%"=="f"                                set "_ValidF=TRUE" && goto TWOPAR_VALID

:TWOPAR_VALID

If "%_DEBUGGING%"=="TRUE" (
    echo TWOPAR Background is %_TPback% %_ValidB%
    echo TWOPAR Foreground is %_TPfore% %_ValidF%
    pause
)

rem I think I can remove this as the color command
rem will provide the errolevel if the values are equal...
rem Is that right?
rem if Background Parameter matches Foreground ignore
rem IF "%_TPback%"=="%_TPfore%" (
rem     set _TrueIFMatch=%errorlevel%
rem     exit %_TrueIFMatch%
rem ) 

if "%_ValidB%"=="TRUE" (
    if "%_ValidF%"=="TRUE" (
        color %_TPback%%_TPfore%
    )
)
exit /B

rem ***********************************************************
rem * Display Help and exit                                   *
rem ***********************************************************

:HELP
@echo off
echo.
echo Sets the default console background and foreground text colors.
echo. 
echo EASYCOLOR ^[Background Decimal Code^]  ^[Text Decimal Code^]
echo EASYCOLOR ^[Background   Color-Name^]  ^[Text Color-Name^]
echo.
echo EASYCOLOR is compatable with the COLOR command see color /?
echo.
echo EASYCOLOR ^[Background HEX CODE Text HEX CODE^]
echo. 
echo Color attributes are specified by Decimal, Color-Names, or Hex digits
echo The first  ^(Decimal, Color-Names, Hex^) value corresponds to the background color;
echo the second ^(Decimal, Color-Names, Hex^) value corresponds to the text color.
echo Each attribute can be any of the following values:
echo. 
echo     Decimal == Color-Names == Hex
echo     _____________________________
echo          0  == Black ======== 0
echo          1  == Blue ========= 1
echo          2  == Green ======== 2
echo          3  == Aqua ========= 3
echo          4  == Red ========== 4
echo          5  == Purple ======= 5
echo          6  == Yellow ======= 6
echo          7  == White ======== 7
echo          8  == Gray ========= 8
echo          9  == LightBlue ==== 9
echo          10 == LightGreen === A
echo          11 == LightAqua ==== B
echo          12 == LightRed ===== C
echo          13 == LightPurple == D
echo          14 == LightYellow == E
echo          15 == BrightWhite == F
echo.
echo Help Examples:
echo.
echo EASYCOLOR                  ^> produces this help screen.
echo EASYCOLOR /?               ^> produces this help screen.
echo.
echo Decimal and Color-Names Examples:
echo.
echo EASYCOLOR 7 0              ^> White background with Black text.
echo EASYCOLOR Blue White       ^> Blue  background with White text. 
echo EASYCOLOR 0 LightGreen     ^> Black background with LightGreen text.
echo.
echo Color command and compatable Hex Examples: 
echo (Note: Hex is assumed if no space between attributes)
echo.
echo EASYCOLOR 0F               ^> Black background with BrightWhite text. 
echo EASYCOLOR 1B               ^> Blue  background with LightAqua text. 
echo.
echo Note
echo.
echo EASYCOLOR 0brightwhite     ^> Black background with LightAqua text.
echo Because there wasn't a space between 0 and brightwhite
echo the HEX value of 0b is assumed; wrongly.
echo. 
echo EASYCOLOR 0 brightwhite    ^> Black background with brightwhite text.
echo as expected.
echo.
echo The EASYCOLOR command sets ERRORLEVEL to 1 if an attempt is made to execute
echo the EASYCOLOR command with a foreground and background color that are the
echo same.
echo. 
echo. 
exit /B

Click here to download the complete solution

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:02:13+00:00Added an answer on May 18, 2026 at 10:02 am

    nice script for the first one.

    But one error I found here

    REM IF TWO PARMETERS GIVEN
    IF NOT "%2"=="" call :TWOPAR %1 %2
    
    REM IF ONE PARMETER GIVEN
    set _OPback=%1
    call :TWOPAR %_OPback:~0,1% %_OPback:~1,1%
    

    If two parameters present, you call :TWOPAR, but it will return, so the “ONE PARMETER GIVEN” part will also be executed.

    And another general code suggestions.

    Don’t repeat yourself 🙂
    If code blocks are nearly same, it is better to merge them to a function.
    Like your two verifications of the color names for the background and forground color.

    @echo off
    setlocal EnableDelayedExpansion
    
    if "%1"=="/?" goto HELP
    if "%1"==""   goto HELP
    
    goto BYPASSREMSTATEMENTS
    rem ***********************************************************
    rem * Easycolor was created by Edoctoor 2010                  *
    rem * With the help from the good people at stackoverflow.com *
    rem * For the good people at stackoverflow.com                *
    rem *                                                         *
    rem * Convert Color-name and Decimals Parmeters to Hex values *
    rem * then pass the VALUES to the COLOR COMMAND               *
    rem ***********************************************************
    :BYPASSREMSTATEMENTS
    
    set "_DEBUGGING=FALSE"
    If "%_DEBUGGING%"=="TRUE" prompt=$g && echo on && cls
    
    REM IF TWO PARMETERS GIVEN
    IF NOT "%2"=="" call :TWOPAR %1 %2 & goto :eof
    
    REM IF ONE PARMETER GIVEN
    
    set _OPback=%1
    call :TWOPAR %_OPback:~0,1% %_OPback:~1,1%
    
    goto :eof
    
    rem ***********************************************************
    rem * Convert Color-name and Decimals Parmeters to Hex values *
    rem * then pass the VALUES to the COLOR COMMAND               *
    rem ***********************************************************
    
    :TWOPAR
    set "_TPback=%1"
    set "_TPfore=%2"
    
    call :AnalyzeParam _TPback _ValidB
    call :AnalyzeParam _TPfore _ValidF
    
    If "%_DEBUGGING%"=="TRUE" (
        echo TWOPAR Background is %_TPback% %_ValidB%
        echo TWOPAR Foreground is %_TPfore% %_ValidF%
        pause
    )
    
    rem I think I can remove this as the color command
    rem will provide the errolevel if the values are equal...
    rem Is that right?
    rem if Background Parameter matches Foreground ignore
    rem IF "%_TPback%"=="%_TPfore%" (
    rem     set _TrueIFMatch=%errorlevel%
    rem     exit %_TrueIFMatch%
    rem ) 
    
    if "%_ValidB%"=="TRUE" (
        if "%_ValidF%"=="TRUE" (
            color %_TPback%%_TPfore%
        )
    )
    exit /B
    
    :AnalyzeParam <paramVariable>
    setlocal EnableDelayedExpansion
    set "value=!%1!"
    set "valid=FALSE"
    
    set "color[0]=Black"
    set "color[1]=Blue"
    set "color[2]=Green"
    set "color[3]=Aqua"
    set "color[4]=Red"
    set "color[5]=Purple"
    set "color[6]=Yellow"
    set "color[7]=White"
    set "color[8]=Gray"
    set "color[9]=LightBlue"
    set "color[10]=LightGreen"
    set "color[11]=LightAqua"
    set "color[12]=LightRed"
    set "color[13]=LightPurple"
    set "color[14]=LightYellow"
    set "color[15]=BrightWhite"
    for /L %%n in (0,1,15) DO (
        if /I !color[%%n]!==!value! (
            set "value=%%n"
            set "valid=TRUE"
            goto :AnalyzeParam_valid
        )
    )
    rem Test if it is a legal hex nibble character
    if /I !value! GEQ A (
        if !value! LEQ F (
            set "valid=TRUE"
        )
    ) ELSE if !value! GEQ 0 (
        if !value! LEQ 9 (
            set "valid=TRUE"
        )
    )
    :AnalyzeParam_valid
    (
       ENDLOCAL
       set %~1=%value%
       set %~2=%valid%
       goto :eof
    )
    

    hope it helps
    jeb

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just finished read this post by Greg Young, where he is talking about Microsoft
I just finished reading this post: https://developer.yahoo.com/performance/rules.html#flush and have already implemented a flush after
I just finished reading this article on the advantages and disadvantages of exceptions and
Just finished a little app that I want to distribute and at the moment
I just finished building my program, but I noticed that vb.net (2010) creates two
I've just finished putting together a basic flash video chat client that publishes the
I have a project that I've just finished painstakingly rebuilding because duplicating a target
I just finished a small project where changes were required to a pre-compiled, but
I just finished a medium sized web site and one thing I noticed about
I just finished a test as part of a job interview, and one question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.