im at it again

Discussion in 'Software' started by red death68, Jan 6, 2011.

  1. red death68

    red death68 Command Sergeant Major

    ok so im trying to learn some batch on my own so i thought it would be a good idea to make a batch file to change the color of cmd prompt but so far it aint working im having issues trying to turn andswers into variable s then use the variables to cchose the colors

    heres what i have (note iv only added 0 for background and 9 for font just for testing purposes)

    Code:
    @echo off &setlocal
    color 09
    echo.
    echo welcome to the cmd prompt color changer
    echo.
    pause
    
    :choice
    REM check for change in background color, or not
    set /p "answer=Would you like to change the background color of your cmd prompt? [y/n] "
    if /i "%answer%" == "y" goto :color choice
    if /i "%answer%" == "n" goto :font color
    echo You have selected an invalid option.
    goto :choice
    
    :color choice
    
    echo.
    echo.
    echo.
    echo What color would you like to change your background to?
    echo.
    echo .0) black
    echo .1) blue
    echo .2) green
    echo .3) aqua
    echo .4) red
    echo .5) purple
    echo .6) yellow
    echo .7) white
    echo .8) gray
    echo .9) light blue
    echo .A) light green
    echo .B) light aqua
    echo .C) light red
    echo .D) light purple
    echo .E) light yellow
    echo .F) bright white
    
    REM check for color change, or no color change
    >nul set /p "answer=What color would you like?[0/1/2/3/4/5/6/7/8/9/A/B/C/D/E/F] "
    if /i "%answer%" == "0" goto :set color
    if /i "%answer%" == "1" goto :set color
    if /i "%answer%" == "2" goto :set color
    if /i "%answer%" == "3" goto :set color
    if /i "%answer%" == "4" goto :set color
    if /i "%answer%" == "5" goto :set color
    if /i "%answer%" == "6" goto :set color
    if /i "%answer%" == "7" goto :set color
    if /i "%answer%" == "8" goto :set color
    if /i "%answer%" == "9" goto :set color
    if /i "%answer%" == "A" goto :set color
    if /i "%answer%" == "B" goto :set color
    if /i "%answer%" == "C" goto :set color
    if /i "%answer%" == "D" goto :set color
    if /i "%answer%" == "E" goto :set color
    if /i "%answer%" == "F" goto :set color
    echo You have selected an invalid option.
    goto :color choice
    
    pause
    
    :set color
    >nul set color=%answer%
    goto :font
    
    :font color
    echo.
    echo.
    echo.
    echo What color would you like to change your font to?
    echo.
    echo .0) black
    echo .1) blue
    echo .2) green
    echo .3) aqua
    echo .4) red
    echo .5) purple
    echo .6) yellow
    echo .7) white
    echo .8) gray
    echo .9) light blue
    echo .A) light green
    echo .B) light aqua
    echo .C) light red
    echo .D) light purple
    echo .E) light yellow
    echo .F) bright white
    
    REM check for color change, or no color change
    >nul set /p "answer=What color would you like?[0/1/2/3/4/5/6/7/8/9/A/B/C/D/E/F] "
    if /i "%answer%" == "0" goto :set font
    if /i "%answer%" == "1" goto :set font
    if /i "%answer%" == "2" goto :set font
    if /i "%answer%" == "3" goto :set font
    if /i "%answer%" == "4" goto :set font
    if /i "%answer%" == "5" goto :set font
    if /i "%answer%" == "6" goto :set font
    if /i "%answer%" == "7" goto :set font
    if /i "%answer%" == "8" goto :set font
    if /i "%answer%" == "9" goto :set font
    if /i "%answer%" == "A" goto :set font
    if /i "%answer%" == "B" goto :set font
    if /i "%answer%" == "C" goto :set font
    if /i "%answer%" == "D" goto :set font
    if /i "%answer%" == "E" goto :set font
    if /i "%answer%" == "F" goto :set font
    echo You have selected an invalid option.
    goto :font color
    
    :set font
    >nul set color2=%answer%
    goto :finish
    
    :finish
    color %color%%color2%
    pause
    
    echo test
    pause
     
  2. PC-XT

    PC-XT Master Sergeant

    That code works for me with no changes on XP...
     
  3. red death68

    red death68 Command Sergeant Major

    wow am i stupid i forgot 09 works out to my default colors

    man i realy should get more sleep before messing with batch codes
     
  4. red death68

    red death68 Command Sergeant Major

    well through some expirementing and major rewrites in certain areas i have fully completed the code and it also now has a cls function that relocates u back to the users root directory of C:\Documents and Setting\%username%\

    let me know what your think and if theres any thing i could do to get better with it

     
  5. GermanOne

    GermanOne Guest

    You could try to write it without all these redundant phrases.
    Maybe something like that:
    Code:
    @echo off &setlocal enabledelayedexpansion &color 09
    echo( &echo welcome to the cmd prompt color changer &echo(
    
    :choice
    set /p "answer=Would you like to change the color of your cmd prompt? [y/n] "
    if /i "%answer%"=="n" goto :eof
    if /i "%answer%" neq "y" (echo You have selected an invalid option. &goto :choice)
    
    for %%a in (
      "0 black" "1 blue" "2 green" "3 aqua" "4 red" "5 purple" "6 yellow"
      "7 white" "8 gray" "9 light blue" "A light green" "B light aqua"
      "C light red" "D light purple" "E light yellow" "F bright white"
    ) do for /f "tokens=1*" %%b in (%%a) do set "col_%%b=%%c"
    cls &call :color_choice background color
    cls &call :color_choice font color2
    
    color %color%%color2% &endlocal &cls
    cmd /k cd /d "%userprofile%" &goto :eof
    
    :color_choice
    set Answer=" &echo(
    echo What color would you like to change your %1 to? &echo(
    for /f "tokens=2,3 delims==_" %%a in ('set col_') do echo .%%a) %%b
    set /p "answer=What color would you like?[0/1/2/3/4/5/6/7/8/9/A/B/C/D/E/F] "
    if "!col_%answer%!"=="" (cls &echo You have selected an invalid option. &goto :color_choice)
    set "%2=%answer%" &goto :eof
    
    
    Regards
    GermanOne
     
  6. red death68

    red death68 Command Sergeant Major

    thanks german yours seems kinda complex but i see where it came from i tend to go the long about route to make sure i dont mess anything up

    but i like your set up as well


    other then the obvious redundency how is it? i primarly did it to get used to using variable strings
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds