|
huzixuan
高级用户
   
积分 537
发帖 219
注册 2006-10-31 来自 芜湖
状态 离线
|
 『楼 主』:
批处理日历
使用 LLM 解释/回答一下
就要过年了,小弟将日历献上.,有更好更方便更简洁的方法请讨论一下.
代码中有不妥之处请大家踊跃批评............
祝:新年快乐,万事如意. 猪年诸事行大运!!
@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=查几月?
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 ]
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 ]
此帖被 +18 点积分 点击查看详情 评分人:【 redtek 】 | 分数: +10 | 时间:2007-2-17 06:53 | 评分人:【 namejm 】 | 分数: +4 | 时间:2007-2-21 07:43 | 评分人:【 maobin 】 | 分数: +2 | 时间:2007-2-24 09:38 | 评分人:【 my3439955 】 | 分数: +2 | 时间:2007-4-24 10:49 |
|
|

江湖远
碧空长
路茫茫
一个人漫无目的的奔跑,风,刺骨的冷.... |
|
2007-2-17 00:00 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
加上几几年的就更完美了...
Adding the year would be even more perfect...
|
|
2007-2-17 00:12 |
|
|
huzixuan
高级用户
   
积分 537
发帖 219
注册 2006-10-31 来自 芜湖
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
因本人尚处于学飞阶段,还无法实现更复杂的功能,因此还需兄们的帮助才可以完成.
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.
|

江湖远
碧空长
路茫茫
一个人漫无目的的奔跑,风,刺骨的冷.... |
|
2007-2-17 00:17 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
for %%b in (31,28,31,30,31,30,31,31,30,31,30,31) do (
2月一定是28天?
for %%b in (31,28,31,30,31,30,31,31,30,31,30,31) do (
Is February always 28 days?
|
|
2007-2-17 00:42 |
|
|
huzixuan
高级用户
   
积分 537
发帖 219
注册 2006-10-31 来自 芜湖
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
07年的不是吗;) 并且确实想写一个N年通用的,不会呢....
Last edited by huzixuan on 2007-2-17 at 01:00 AM ]
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 ]
|

江湖远
碧空长
路茫茫
一个人漫无目的的奔跑,风,刺骨的冷.... |
|
2007-2-17 00:59 |
|
|
xycoordinate
中级用户
  
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
set j!a!=%%a
set s!y!=%%b
set /a day+=!s%%c!
for /l %%d in (1,1,!day!) do (
set /a b+=1
if !b! equ 8 set b=1)
以上的几行中的“!”代表什么意思???
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.
|
|
2007-2-17 01:33 |
|
|
huzixuan
高级用户
   
积分 537
发帖 219
注册 2006-10-31 来自 芜湖
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
天那,我可怜的小日历还没有得到更多人的鼓励就已经沉入海底了.....
Oh, my poor little calendar has sunk to the bottom of the sea without getting more people's encouragement.....
|

江湖远
碧空长
路茫茫
一个人漫无目的的奔跑,风,刺骨的冷.... |
|
2007-2-17 04:19 |
|
|
gne3
高级用户
    DOS学徒
积分 526
发帖 252
注册 2007-2-12
状态 离线
|
|
2007-2-17 05:20 |
|
|
huzixuan
高级用户
   
积分 537
发帖 219
注册 2006-10-31 来自 芜湖
状态 离线
|
|
2007-2-17 06:16 |
|
|
huzixuan
高级用户
   
积分 537
发帖 219
注册 2006-10-31 来自 芜湖
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
感谢 兄的鼓励,特别感谢 redtek 兄,虽然没有露面,但我知道兄一直都是在帮助我们的
Thanks to the brother's encouragement, especially to brother redtek. Although not appearing, I know that the brother has always been helping us.
|

江湖远
碧空长
路茫茫
一个人漫无目的的奔跑,风,刺骨的冷.... |
|
2007-2-17 23:13 |
|
|
juventusryp
初级用户
 
积分 88
发帖 40
注册 2006-12-26
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
set j!a!=%%a
这句不是很明白,不知道LZ可否解释一下
set j!a!=%%a
I don't quite understand this sentence. I wonder if the LZ can explain it.
|
|
2007-2-19 09:25 |
|
|
xycoordinate
中级用户
  
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Originally posted by juventusryp at 2007-2-18 08:25 PM:
set j!a!=%%a
这句不是很明白,不知道LZ可否解释一下
在大家的帮助下,终于知道了!!!
setlocal enabledelayedexpansion
set /?
......
考虑到读取一行文本时所遇到的目前扩充的限制时,延迟环境
变量扩充是很有用的,而不是执行的时候。以下例子说明直接
变量扩充的问题:
set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "%VAR%" == "after" @echo If you see this, it worked
)
不会显示消息,因为在读到第一个 IF 语句时,BOTH IF 语句中
的 %VAR% 会被代替;原因是: 它包含 IF 的文体,IF 是一个
复合语句。所以,复合语句中的 IF 实际上是在比较 "before" 和
"after",这两者永远不会相等。同样,以下这个例子也不会达到
预期效果:
set LIST=
for %i in (*.txt) do set LIST=%LIST% %i
echo %LIST%
原因是,它不会在目前的目录中建立一个文件列表,而只是将
LIST 变量设成找到的最后一个文件。这也是因为 %LIST% 在
FOR 语句被读取时,只被扩充了一次;而且,那时的 LIST 变量
是空的。因此,我们真正执行的 FOR 循环是:
for %i in (*) do set LIST= %i
这个循环继续将 LIST 设成找到的最后一个文件。
延迟环境变量扩充允许您使用一个不同的字符(惊叹号)在执行
时间扩充环境变量。如果延迟的变量扩充被启用,可以将上面
例子写成以下所示,以达到预期效果:
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%
......
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%
......
|
|
2007-2-20 00:01 |
|
|
pxcok
新手上路

积分 12
发帖 6
注册 2007-1-25
状态 离线
|
|
2007-2-20 05:00 |
|
|
huzixuan
高级用户
   
积分 537
发帖 219
注册 2006-10-31 来自 芜湖
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
13楼的兄弟 解释的好清楚.我一直都是这么用,但却说不清楚这到底是什么意思呢!
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!
|

江湖远
碧空长
路茫茫
一个人漫无目的的奔跑,风,刺骨的冷.... |
|
2007-2-20 05:13 |
|
|
huzixuan
高级用户
   
积分 537
发帖 219
注册 2006-10-31 来自 芜湖
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
得到斑竹的鼓励 真是一件令人兴奋的事.!
It's really an exciting thing to get the encouragement from the moderator!
|

江湖远
碧空长
路茫茫
一个人漫无目的的奔跑,风,刺骨的冷.... |
|
2007-2-21 07:45 |
|
|