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-23 20:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch calendar View 4,045 Replies 23
Original Poster Posted 2007-02-17 00:00 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
It's almost New Year, little brother presents the calendar. If there are better, more convenient and simpler methods, please discuss.
There are any improper places in the code, everyone is welcome to criticize............
Wish: Happy New Year, all the best. Good luck in everything in the Year of the Pig!!

@echo off
mode con: lines=12 cols=40
setlocal enabledelayedexpansion
for %%a in (一,二,三,四,五,六,日) do (
set /a a+=1
set j!a!=%%a)

for %%b in (31,28,31,30,31,30,31,31,30,31,30,31) do (
set /a y+=1
set s!y!=%%b)

set /p m=Which month to check?
cls
set n=%m%
set /a n-=1


for /l %%c in (1,1,%n%) do (
set /a day+=!s%%c!)


set b=0

for /l %%d in (1,1,!day!) do (
set /a b+=1
if !b! equ 8 set b=1)

if %m% equ 1 set b=7



echo 一 二 三 四 五 六 日
echo.
set flag= 一二三四五六日一二三四五六日


for /l %%f in (1 1 13) do (

if "!flag:~%%f,1!"=="!j%b%!" (
if "!j%%f!"=="一" (set /p s= <nul&set zh=6&goto next)
if "!j%%f!"=="二" (set /p s= <nul&set zh=5&goto next)
if "!j%%f!"=="三" (set /p s= <nul&set zh=4&goto next)
if "!j%%f!"=="四" (set /p s= <nul&set zh=3&goto next)
if "!j%%f!"=="五" (set /p s= <nul&set zh=2&goto next)
if "!j%%f!"=="六" (set /p s= <nul&set zh=1&goto next)
if "!j%%f!"=="日" (set /p s=<nul&set zh=7&goto next)
))


:next

for /l %%e in (1 1 !s%m%!) do (
set /a b+=1
if !b! equ 8 set b=1
if %%e lss 10 (set /p= %%e<nul) else (set /p= %%e<nul)
if !fl!==0 (set /a z+=1)

if !z!==7 (echo.&set z=0)
if %%e==!zh! (echo.
set fl=0
)
)
pause>nul


[ Last edited by huzixuan on 2007-2-21 at 10:49 PM ]
Recent Ratings for This Post ( 4 in total) Click for details
RaterScoreTime
redtek +10 2007-02-17 06:53
namejm +4 2007-02-21 07:43
maobin +2 2007-02-24 09:38
my3439955 +2 2007-04-24 10:49
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 2 Posted 2007-02-17 00:12 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Adding the year would be even more perfect...
Floor 3 Posted 2007-02-17 00:17 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
Because I am still in the stage of learning to fly and cannot yet achieve more complex functions, so I still need the help of brothers to complete it.
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 4 Posted 2007-02-17 00:42 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
for %%b in (31,28,31,30,31,30,31,31,30,31,30,31) do (

Is February always 28 days?
Floor 5 Posted 2007-02-17 00:59 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
Isn't it from 2007;) And I really want to write something that works for many years, but I don't know how....

[ Last edited by huzixuan on 2007-2-17 at 01:00 AM ]
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 6 Posted 2007-02-17 01:33 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 493
Posts 228
Joined 2007-02-16 00:38
19-year member
UID 79596
Gender Male
From 安徽
Status Offline
In batch scripting, the exclamation marks are used for delayed expansion. When delayed expansion is enabled, variables within loops or conditional blocks can be accessed correctly as their values change during execution. Without delayed expansion, the old value of the variable would be used instead. So in this context, the exclamation marks are related to enabling and using delayed variable expansion in the batch code.
Floor 7 Posted 2007-02-17 04:19 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
Oh, my poor little calendar has sunk to the bottom of the sea without getting more people's encouragement.....
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 8 Posted 2007-02-17 05:20 ·  中国 浙江 台州 温岭市 电信
高级用户
★★
DOS学徒
Credits 526
Posts 252
Joined 2007-02-12 05:35
19-year member
UID 79286
Gender Male
Status Offline
Floor 9 Posted 2007-02-17 06:16 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 10 Posted 2007-02-17 23:13 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
Thanks to the brother's encouragement, especially to brother redtek. Although not appearing, I know that the brother has always been helping us.
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 11 Posted 2007-02-19 09:25 ·  中国 河南 郑州 联通
初级用户
Credits 88
Posts 40
Joined 2006-12-26 07:32
19-year member
UID 74591
Gender Male
Status Offline
set j!a!=%%a
I don't quite understand this sentence. I wonder if the LZ can explain it.
Floor 12 Posted 2007-02-20 00:01 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 493
Posts 228
Joined 2007-02-16 00:38
19-year member
UID 79596
Gender Male
From 安徽
Status Offline
Originally posted by juventusryp at 2007-2-18 08:25 PM:
I don't quite understand this line "set j!a!=%%a". I wonder if the LZ can explain it.

With everyone's help, I finally understand!!!

setlocal enabledelayedexpansion

set /?

......
When considering the current expansion limitations encountered when reading a line of text, delayed environment variable expansion is useful, not at execution time. The following example illustrates the problem with direct variable expansion:

set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "%VAR%" == "after" @echo If you see this, it worked
)

No message will be displayed because when the first IF statement is read, %VAR% in BOTH IF statements will be substituted; the reason is: it contains the style of IF, and IF is a compound statement. So the IF in the compound statement is actually comparing "before" and "after", which will never be equal. Similarly, the following example will not achieve the expected effect:

set LIST=
for %i in (*.txt) do set LIST=%LIST% %i
echo %LIST%

The reason is that it will not create a file list in the current directory, but just set the LIST variable to the last file found. This is also because %LIST% is only expanded once when the FOR statement is read; and at that time, the LIST variable is empty. Therefore, the FOR loop we are really executing is:

for %i in (*) do set LIST= %i

This loop continues to set LIST to the last file found.

Delayed environment variable expansion allows you to use a different character (!) to expand environment variables at execution time. If delayed variable expansion is enabled, the above example can be written as follows to achieve the expected effect:

set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "!VAR!" == "after" @echo If you see this, it worked
)

set LIST=
for %i in (*.txt) do set LIST=!LIST! %i
echo %LIST%
......
Floor 13 Posted 2007-02-20 05:00 ·  中国 广东 东莞 电信
新手上路
Credits 12
Posts 6
Joined 2007-01-25 04:57
19-year member
UID 77596
Gender Male
Status Offline
Floor 14 Posted 2007-02-20 05:13 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
Brother on the 13th floor explained it very clearly. I've always used it this way, but I can't clearly explain what this means!
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 15 Posted 2007-02-21 07:45 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
It's really an exciting thing to get the encouragement from the moderator!
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Forum Jump: