China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 06:50
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Cycle through changing the background color and text color of the cmd window one by one View 4,640 Replies 4
Original Poster Posted 2007-01-15 12:02 ·  中国 四川 绵阳 电信
初级用户
Credits 26
Posts 7
Joined 2006-09-06 05:20
19-year member
UID 61942
Gender Male
From 四川
Status Offline
I want to make the background color and text color of the cmd window change in a cycle one by one (I want to choose a good effect configuration from it). How to write it with for?
After each color change, choose whether to continue the experiment and output the background and text color codes of the current window:
The current background and text color, for example, output 0a
%a% %b% respectively store
Background color and text color, that is like this: select two combinations from 0, 1, 2, 3...9, a, b, c, d, e, f one by one and give them to a, b respectively until all combinations are selected, then use
color %a%%b%
to for loop to choose whether to continue the experiment and display the current configuration

[ Last edited by gskys123 on 2007-1-15 at 12:03 PM ]
Floor 2 Posted 2007-01-15 12:23 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Version 1:

@echo off
setlocal enabledelayedexpansion
set str=0123456789abcdef

for /l %%i in (0,1,15) do (
for /l %%j in (0,1,15) do (
if %%i neq %%j (
cls
echo Current color code is: color !str:~%%i,1!!str:~%%j,1!
color !str:~%%i,1!!str:~%%j,1!
pause
)
)
)

Version 2:

@echo off
for %%i in (0 1 2 3 4 5 6 7 8 9 a b c d e f) do (
for %%j in (0 1 2 3 4 5 6 7 8 9 a b c d e f) do (
if %%i neq %%j (
cls
echo Current color code is: color %%i%%j
color %%i%%j
pause
)
)
)


[ Last edited by namejm on 2007-1-15 at 12:23 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
wangjf +2 2007-03-19 10:18
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2007-01-15 12:43 ·  中国 福建 厦门 电信
初级用户
Credits 49
Posts 20
Joined 2006-04-22 11:03
20-year member
UID 54248
Status Offline
Test the code of namejm, and find: no color such as :10 12 13 14
Floor 4 Posted 2007-01-15 12:48 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
At that time, I only thought about the situation where numbers come before letters and ignored other situations, making a low-level mistake. Sweat. The second floor has been updated.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 5 Posted 2007-01-17 01:23 ·  中国 四川 绵阳 电信
初级用户
Credits 26
Posts 7
Joined 2006-09-06 05:20
19-year member
UID 61942
Gender Male
From 四川
Status Offline
Thanks namejm!! ;)
This way, my understanding of the usage of for has deepened a bit!
Thank you!!
Forum Jump: