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-07-22 07:03
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Scheduled Task Mini Program [Update on 06.12] View 4,038 Replies 19
Original Poster Posted 2006-06-08 19:20 ·  中国 江苏 镇江 联通
中级用户
★★
Credits 219
Posts 82
Joined 2005-10-29 10:56
20-year member
UID 44240
Status Offline
I haven't learned DOS myself. I'm afraid this can be attributed to the relatively late time I got in touch with computers. Fortunately, I found this great place. How happy I was~~~ And I feel that as long as I come here, I will definitely gain something!

First of all, I've been soaking in the forum for more than half a year. My level is very low, and I approach any problem with a learning attitude. But fortunately, the atmosphere of the whole forum is very good. In addition to the active attitude of the forum members, more importantly, there are a group of enthusiastic and highly skilled moderators here. They can be said to be very good teachers for us. Here, I would like to express my gratitude to the friends who have helped me.

I spent 2 days writing this small program. I mainly wanted to use what I've learned here in one go. Of course, it's a relatively low-level program. I hope you don't laugh at it and give me support.

Please let me know if there are any improper or incorrect places in my writing. I'm very willing to accept suggestions.

Change time: 2006.6.9 10:00
Spent some time in the morning adding comments, which is equivalent to checking the existing problems again by myself. Sure enough, I found a few problems. :P, the attachment hasn't been updated, and there are several problems with upper and lower cases


Change time 2006.6.12 13:00, added inspection of time and date


==========ETIME========
@echo off
color 1f
echo.
echo Scheduled Plan Tool VER:1.0
echo by: Fengchi Network, jastyg
echo Email:support@efengchi.com
echo HTTP://WWW.EFENGCHI.COM
echo for xp/2k3
echo.
echo.

rem ++++++++++++++++++++Processing in external command line mode+++++++++++++++++++++++++++

rem ===================Check if the external input is empty or is help information============
if "%1!%"=="!" goto guihelp :If the external input is empty, use the graphical page
if "%1%"=="/?" goto help :If the external input is /?, show the DOS help prompt
if "%1%"=="/h" goto help :Same as above, input /h
if "%1%"=="/H" goto help :Same as above, respectively give cases.
for %%i in (0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31) do if "%1"=="%%i" goto kaishi
goto warng2

rem====================Start setting and checking the external input==================
:kaishi
if "%1"=="0" set d=0&set riqi=0& goto t :If the initial date is 0
set /a tmp=%date:~8,3%+0 >nul :Judge if the date is the 8th or 9th, to connect with the following (method to solve invalid characters of 8 and 9)
cls :Clear screen
if errorlevel 9167 goto tmp1 :Connect with the above to accept if it is the 8th or 9th
goto tmp2

rem====================Determine the date of the 8th and 9th========================
:tmp1
echo %date:~8,2% >tem.txt :Export the current date to a temporary file
find "08" tem.txt >nul :Find whether the value 08 is contained in the temporary file, to connect with the following
if not errorlevel 1 set riqi=8&goto tmp3 :Judge if 08 is contained, then set the riqi variable to 8, jump to TMP3 label
find "09" tem.txt >nul :Find whether the value 09 is contained in the temporary file, to connect with the following
if not errorlevel 1 set riqi=9&goto tmp3 :Judge if 09 is contained, then set the riqi variable to 9, jump to TMP3 label

rem====================Processing when the external date is not 0, 8, 9===============
:tmp2
set /a riqi=%date:~8,2%+0 :Process the case where the tens digit of the date is empty to remove 0
:tmp3
set /a d=%1+0 :Process the case where the tens digit of the user input date is empty to remove 0

rem===================Process the external time and user command=================================
:t
if exist tem.txt del tem.txt :Clean up the temporary file left after setting the date
set t=%2 :Define variable T as the user input time
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,) do if "%t:~0,2%"=="%%i" goto CRC
goto warng2
:CRC
if "%t:~2,1%"==":" goto CRC1
goto warng2
:crc1
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,) do if
"%t:~3,2%"=="%%i" goto bcmd
goto warng2

:bcmd

set cmd=%~3 :Define the running program as the user input
if "%~3!"=="!" goto command :If the user doesn't input, jump to the default set value, to COMMAND
goto 4

:command
set cmd=c:\windows\Fengchi Backup.bat :Set the default running command

rem===================Set external loop option command==========================================
:4
if "%4!%"=="!" goto 41 :Judge if it is empty and jump relatively
if "%4%"=="n" goto 41 :Judge if it is lowercase n and jump relatively
if "%4%"=="N" goto 41 :Whether it is uppercase N and jump relatively
if "%4%"=="y" goto 42 :Whether it is lowercase y and jump relatively
if "%4%"=="Y" goto 42 :Whether it is uppercase Y and jump relatively

rem===================Set default and no loop==============================================
:41
set rem=echo. :Define variable as echo.
goto start :Jump to the part of checking date and time

:42
set rem=goto start :Define variable as goto statement, realize loop
set yanchi=ping -n 60 127.1^>nul :To prevent the time from running multiple times within the specified time, set a delay of 1 minute
goto start :Jump to the part of checking date and time
echo.

rem ++++++++++++++++++++Graphical setting and configuration processing++++++++++++++++++++++++++++++++++++++++
rem===================Graphical help prompt================================================
:guihelp
echo Please wait......
ping -n 1 ping 127.1 >nul
cls
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo +Usage 1: Directly run this file and follow the wizard. Enter? or h for help +
echo +Date format: For example, 9th, you can enter 9 or 09 +
echo +Time format adopts 24-hour system, that is: 20:50 (precision to minutes) +
echo +Usage 2: Command line mode; +
echo +Syntax: etime day time command (it's better to write the full path) Y/N (whether to run in loop, default is N) +
echo +Example: etime 7 20:20 notepad.exe (Run the NOTEPAD program at 20:20 on the 7th, and don't loop) +
echo +Example: etime 0 20:20 notepad.exe Y (Run the NOTEPAD program at 20:20, and loop) +
echo +Enter etime /? or etime /h in DOS to get help +
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

rem===================Detect and define the user input date==================================
:begin
echo Please enter date
set d1=enter :Define a value for D1, to detect if the user input is empty in the following
set /p d1= :User-defined input
if "%d1%"=="?" goto guihelp :Call graphical help
if "%d1%"=="h" goto guihelp :Same as above
if "%d1%"=="H" goto guihelp :Same as above
if "%d1%"=="enter" goto warng :Detect if the user input is empty, and process relatively
if "%d1%"=="0" set d=0&set riqi=0& goto shij :Detect if the user input is 0, and relatively define
for %%i in(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,?,h,H,) do if "%
d1%"=="%%i" goto 89
goto warng
:89

set /a tmp=%date:~8,3%+0 >nul :Judge if the date is the 8th or 9th, to connect with the following (method to solve invalid characters of 8 and 9)
cls
if errorlevel 9167 goto tem1 :Connect with the above to accept if it is the 8th or 9th, and jump relatively
goto tem2

rem====================Determine the date of the 8th and 9th, same as TMP1========================
:tem1
echo %date:~8,2% >tem.txt
find "08" tem.txt >nul
if not errorlevel 1 set riqi=8&goto tem3
find "09" tem.txt >nul
if not errorlevel 1 set riqi=9&goto tem3

rem====================Processing when the date is not 0, 8, 9, same as TMP2===============
:tem2
set /a riqi=%date:~8,2%+0

:tem3
set /a d=%d1%+0

rem===================Process time and user command=================================
:shij
if exist tem.txt del tem.txt :Clean up the temporary file left after setting the date
cls
echo Please enter time
set t=enter :Define a value for T, to detect if the user input is empty in the following
set /p t= :User-defined input
if "%t%"=="?" goto guihelp :Call graphical help
if "%t%"=="h" goto guihelp :Same as above
if "%t%"=="H" goto guihelp :Same as above
if "%t%"=="enter" goto warng1 :Detect if the user input is empty, and process relatively
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,?,h,H) do if "%t:~0,2%"=="%%i" goto TCRC
goto warng1
:TCRC
if "%t:~2,1%"==":" goto TCRC1
goto warng1
:tcrc1
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,) do if
"%t:~3,2%"=="%%i" goto cmd
goto warng1


rem==================Process user command===========================================
:cmd
echo Please enter the path and file name of the file to be executed
set cmd=enter
set /p cmd=
if "%cmd%"=="?" goto guihelp
if "%cmd%"=="h" goto guihelp
if "%cmd%"=="H" goto guihelp
if "%cmd%"=="enter" goto command1
goto xunhuan

:command1
set cmd=c:\windows\Fengchi Backup.bat

rem==================Define whether to loop================================================
:xunhuan
echo Whether to run in loop? Y/N
set rem=enter
set /p rem=
if "%rem%"=="y" goto 14
if "%rem%"=="Y" goto 14
if "%rem%"=="enter" goto 24
if "%rem%"=="n" goto 24
if "%rem%"=="N" goto 24

:14
set rem=goto start
set yanchi=ping -n 60 127.1^>nul
goto start

:24
set rem=rem goto
cls

rem==================Detection and relative processing of current date time and user input date time========================
:start
if "%riqi%%time:~0,5%"=="%d% %t%" goto run
ping -n 15 127.1>nul

rem==================DOS help prompt=======================================================
:help
chcp 936 >nul
echo Syntax: etime day time command (it's better to write the full path) Y/N (whether to run in loop, default is N)
echo Example: etime 7 20:20 notepad.exe (Run the NOTEPAD program at 20:20 on the 7th, and don't loop)
echo Example: etime 7 20:20 "del c:\aaa.txt" (Delete a specific file at the specified time)
echo Example: etime 0 20:20 notepad.exe Y (Run the NOTEPAD program at 20:20, and loop)
echo Enter etime /? or etime /h in DOS to get help
goto exit

rem==================Input error prompt==========================================================
:warng
echo Your date input is incorrect!
echo.
goto begin


rem==================Input error prompt==========================================================
:warng1
echo Your time input is incorrect!
echo.
goto shij

rem==================Execute user-defined command or default command, and whether to loop==============================
:run
cls
start %cmd% :Execute command
%yanchi% :Delay time connects with the above to prevent multiple runs of the command
%rem% :Define whether to loop
exit :Program ends

rem==================Exit to the prompt=========================================================
:warng2
echo Syntax error!!

:exit



After writing it on the first day, I felt everything was fine. But after several tests by myself, I found many problems. Now I've changed all the problems I know. Currently, I feel very good (of course, the teachers will definitely find many flaws when they see it, hehe)
There is the one I added a shell to in the attachment, which can be used directly. It feels comparable to the AT command.

[ Last edited by jastyg on 2006-6-12 at 16:09 ]
Attachments
etime.rar (63.43 KiB, Credits to download 1 pts, Downloads: 104)
Floor 2 Posted 2006-06-08 20:17 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
I copied and ran your code for a trial run, and initially found the following problems:
1. Each step of operation only has input prompts, but no functional explanations of the input, making it unclear what operation will be executed after input; it is suggested to provide functional prompts for each step of operation;
2. I don't know what command to input to view your help content; even if I input the specified commands such as /? /help, other functions are run; it is suggested to modify the code;
3. There is no need to use @ again to hide the commands after @echo off; it is suggested to delete the duplicate @ to streamline the code;
4. In the code, the naming of labels is sometimes in English and sometimes in pinyin, which is relatively chaotic; the functions of each part are even sometimes represented by numbers, making it difficult to immediately understand what function the content under the label is; it is suggested to unify the naming of labels, preferably so that the name can indicate the meaning;
5. There is no error detection in the input part, and if the input is wrong, the program may have accidents during operation; it is suggested to perform error detection on the input part;
6. When setting variables, variables with specific meanings such as rem, tmp are used, and I personally think it may have an impact on the CMD environment (no further verification has been done, and authoritative conclusions are awaited from various experts); it is suggested to replace them with other characters;
Hehe, I just talked a lot about the shortcomings of your code, hope you don't mind.
I am currently improving a file backup script program, and hope you can pay attention to it. Part of the code will be helpful for you to improve this script, and at the same time, I hope you can give some suggestions on my script.
The following is the address of my script in this forum:
File Backup Tool: http://www.cn-dos.net/forum/viewthread.php?tid=20747&fpage=0&highlight=&page=1

[ Last edited by namejm on 2006-6-8 at 20:30 ]
Floor 3 Posted 2006-06-08 20:43 ·  中国 江苏 镇江 联通
中级用户
★★
Credits 219
Posts 82
Joined 2005-10-29 10:56
20-year member
UID 44240
Status Offline
1. Each step of the operation only has input prompts, but no functional explanations for the input, making it unclear what operation will be performed after input; it is suggested to provide functional prompts for each step of the operation;

I think this is not necessary to explain in detail. It should be okay to just follow the guide.

2. Don't know what command to enter to view your help content; even if entering the specified commands like /? /help, other functions are run; it is suggested to modify the code;

Here, under XP/2K3, entering etime /? or etime /h can be viewed. I don't know what system you have? 2000 has no environment, so I can't test it.

3. The @echo off command doesn't need to use @ again to hide the subsequent commands; it is suggested to delete the duplicate @ to streamline the code; I am ignorant and didn't find the excess, please point it out clearly, thank you

4. In the code, the labeling is sometimes in English and sometimes in pinyin, which is relatively chaotic; the functions of each part are even sometimes represented by numbers, making it difficult to immediately understand what function is under this label; it is suggested to unify the labeling, preferably so that the meaning can be known from the name;

This is because I didn't think very comprehensively when designing it at that time, resulting in many problems during testing, and I had to make do. Hehe

5. There is no error detection in the input part, and if the input is wrong, the program may have accidents during operation; it is suggested to perform error detection on the input part;

Simple input detection has been done. I think when asking you to enter the day, the most common is to enter, for example, on the 7th, generally 07 OR 7. I can't imagine that the user would enter 70?

6. When setting variables, rem, tmp and other variables with specific meanings are used. Personally, I think it will affect the CMD environment (no further verification has been done, waiting for experts to give authoritative conclusions), it is suggested to replace them with other characters;

This is indeed a defect. Thank you for clearly pointing it out. But fortunately, my current test hasn't reached the point of affecting use yet


Thank you for your valuable suggestions. Many problems are inevitable during the learning process, and I will accept your suggestions.
Floor 4 Posted 2006-06-08 21:48 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Re jastyg:

  Still pondering how your script works : )
  According to the general habit of people using bat programs, usually they double-click the script to run it. No one would open the cmd window first and then enter the full path of the bat program to run it. So, in the first interface that opens after double-clicking the bat, there should have the function introduction of the program, or prompt to enter a certain command or character to view the help content of the script. It is precisely because of this habit issue that when double-clicking the script to run, directly entering /? to view the help of your script results in irrelevant help content, almost making me doubt if my CMD is malfunctioning : )
  In the line @color 1f after @echo off, the @ can be removed.
  Regarding the error detection section, my opinion is like this: If when entering, you accidentally just press Enter, that is, when the input is empty, the operation will have an accident - you can't guarantee that others will input correctly all the time. There are other situations of input errors, so please consider more for careless users. Another situation: In your code, the time entry is very problematic without explanation. Exactly, should you enter the integer point of time, or the format with colons? Should it be precise to seconds?...
  Because in batch processing, rem is for comments, and %tmp% refers to the temporary file directory. Setting them as variables is okay in your current script, but it is still recommended not to set batch processing commands or system environment variables as variables, so as to avoid mistakes when getting confused when referencing with a large amount of code. Good code writing habits are a great guarantee for writing correct code, what do you think?
  If you want to pursue perfection, there are many places worth improving: for example, consider removing the drop-down bar of the CMD window to prevent novices from getting lost in the content after randomly pulling it.
  Hehe, always picking on your flaws, hope you don't mind again.
Floor 5 Posted 2006-06-08 22:08 ·  中国 江苏 镇江 联通
中级用户
★★
Credits 219
Posts 82
Joined 2005-10-29 10:56
20-year member
UID 44240
Status Offline
re: namejm
Brother's statement makes a lot of sense. Maybe it's because I haven't written a program myself, and I really didn't think through things very comprehensively.
In the line @color 1f, the @ was a momentary oversight of mine. Because there were many problems during the program testing, so I directly added @echo off in the first line for easier testing. Regarding the empty input, I have already thought about how to handle it, thank you for the reminder. The instructions really should be added at the beginning of the program for clearer understanding. The time format is like 20:05.

Brother's suggestions to me have benefited me a lot. My original intention was also to release what I wrote for everyone to see, and what I hope to get is to have my deficiencies pointed out. I'm really grateful to you.

I just read brother's post, and I admire your patience and level. I didn't finish reading your post. For one thing, I don't have patience, and for another, I don't understand many places. Please forgive me~~~~
Floor 6 Posted 2006-06-08 23:05 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Regarding my level, actually you can tell from my registration time; also, my current job is far removed from the computer field, and it's hard for outsiders to connect the two. It's just that I'm very interested in computers, so I've been lurking in the forum :) I've learned a lot here, and I really thank the many experts here. Hehe, it seems I've strayed a bit.

Hehe, I'm going to pick on your faults again ha—It seems like I'm specifically picking on you, don't throw bricks at me.

The two lines goto kaishi and :kaishi, since they are right next to each other, according to the execution order of bat commands, which is top-to-bottom execution (except for jumps), so the goto kaishi line can be omitted;
In the line if "%1"=="0" set d=0&set riqi=0& goto t, the set d=0 and set riqi=0 can be omitted. In CMD, there's no need to initialize variable values (hehe, is there such a saying as "initialization" in CMD? I'm not very懂 either, I'll call it that for now). Of course, doing this also doesn't cause errors in running;(Later, referring to other posts, I found that this statement is wrong. Setting the initial value to 0 is necessary)
What's the role of +0 in the line set /a tmp=%date:~8,3%+0 >nul?
What's the meaning of the error code 9167 in the line if errorlevel 9167 goto tmp1? Is it a statement to judge the operating system version? I don't understand very well, please explain;
The几句 echo %date:~8,2% >tem.txt find "08" tem.txt >nul if not errorlevel 1 set riqi=8&goto tmp3 are not very understandable: Why look for the character "08"? What's the role?
After each input is completed, it's recommended to use the cls command to clear the screen, don't let the previous input remain on the screen.
Also, I feel that when you write the code, the logic isn't very smooth. It's recommended to string the code in the following order: first write the code for each step when input is correct together, then put the code with branch flows together, and finally put all the error detection codes together. Each section of code labeled with a label should preferably have comments to indicate the function of this section, and you can consider adding comments where important. If you do this, it will make it very easy for people to see the logical structure of the code you wrote. It's not only convenient for you to quickly find the position when improving the code later, but also makes it easy for others to see where the errors are.
Due to my limited level, I've only raised the above few questions for now. There are more areas that can be improved, and everyone needs to discover them.

[ Last edited by namejm on 2006-6-9 at 00:36 ]
Floor 7 Posted 2006-06-08 23:34 ·  中国 江苏 镇江 联通
中级用户
★★
Credits 219
Posts 82
Joined 2005-10-29 10:56
20-year member
UID 44240
Status Offline
re: namejm

According to your hint, I have made some modifications. It's really tiring to make large-scale changes, heh heh!

What's the function of +0 in the sentence set /a tmp=%date:~8,3%+0 >nul?
Actually, I have no choice. You should carefully look at SET/? and you will get 08, 09 are invalid numbers because 8 and 9 are not valid octal digits.
So running the above code will cause an error. By echo %errorlevel % we get errorlevel =9167.
Because 8 and 9 are invalid, so if the input date is 8 or 9, my program can't be correct (PS: yesterday was the 7th, I tested it well, but today it's not working, and then I found this problem, and it's okay except for 8 and 9)
echo %date:~8,2% >tem.txt find "08" tem.txt >nul if not errorlevel 1 set riqi=8&goto tmp3 
By exporting the characters showing the day in the specified date to TEM.TXT and then searching, if there is 8, set %riqi%=8 (that is, the 8th), and similarly get the 9th.
Because I determine whether the values are consistent by if "%riqi%%time:~0,5%"=="%d%%t%", so I go to run.

Indeed, the logic is much worse, please forgive me, heh heh. It's enough to be able to use it~~~.
With this experience, it should be much better in the future~~
Thanks for your patient guidance
It's getting late, go to bed early. Looking forward to your reply tomorrow~~~

PS: I also found that there are still some problems and deficiencies. I want to see if I can solve them tomorrow, such as users mistakenly entering special symbols, etc. I hope you can give good ideas.

[ Last edited by jastyg on 2006-6-8 at 23:40 ]
Floor 8 Posted 2006-06-09 00:00 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Compared with the more than 700 lines of code in my file backup tool (but many are rem and echo statements, which is an exaggerated statement I made on purpose), your code with more than 100 lines is considered small. But I can still quickly find out where the problem is, which is precisely due to the fact that I sorted out the logical order relatively well at the very beginning (I don't dare to say it's the best logical order). I hope you can also come up with an order that is convenient for your own modification.

Regarding input error detection, it has been discussed a lot in my post about the file backup tool. Just take your time to read it and you will understand.

Here's a suggestion for you: when writing code, try to generate as few temporary files as possible. If you have to generate temporary files, think more about whether you can use the for statement and connectors such as &, &&, |, and || to avoid temporary files.

I still can't fully understand your code, but my intuition tells me that there should be a more concise way to handle the numbers 8 and 9 in the statement set /a tmp=%date:~8,3%+0 >nul. Hehe, ask Boss willsort, he should have a way.
Floor 9 Posted 2006-06-09 00:55 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
to jastyg:

The moderator has marked your post with a red line. You need to work hard and strive to get it pinned or made an essence. ????
I'm going to sleep now~~~~~
Floor 10 Posted 2006-06-09 02:13 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re jastyg:

First of all, "original" code is worthy of appreciation and encouragement, which is the decisive consideration for me to highlight this topic with a red underline.

Secondly, there are many technical details in this topic that can be discussed, so it has the potential to become an essence topic; of course, before that, we first need to initially improve the code in the topic, that is, the framework logic improvement mentioned by Brother namejm, mainly including the relatively independent function of each module, clear and easy-to-understand tag names, and appropriate blank lines as spacing.

Again, it is suggested that your code release method refer to Brother namejm's original topic. The new code will be continuously updated in the first post of the topic, and the changed version number and update date will be marked in the topic title. In addition, it is suggested that when you repost the code, use [code] and [/code] before and after the code, so as to prevent some special characters in the code from being escaped, which is convenient for browsing and copying, and at the same time highlight the particularity of the code.

Finally, regarding the 08/09 problem handed over to me by Brother namejm, this is my consideration. The reason why 08/09 is recognized as an octal number is because the set/a command is used, and I have observed all the set/a statements in the code, which only add zero to the date value, and I can't see what practical meaning it has. Maybe you want to realize the conversion of the date string to an integer value, but this is not needed and difficult to realize in batch processing. All command line programs that can handle integers will automatically convert the string number to an integer value by themselves, because this is an inherent convention in the command line environment.

Of course, the 08/09 problem can be solved more simply. If you really need to perform set/a operation on the date value, I can provide corresponding solutions.

[[i] Last edited by willsort on 2006-6-9 at 02:18 [/i]]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 11 Posted 2006-06-09 08:51 ·  中国 江苏 镇江 电信
中级用户
★★
Credits 219
Posts 82
Joined 2005-10-29 10:56
20-year member
UID 44240
Status Offline
re: namejm
Due to the limitations of my ability, there are actually things I want to do but can't. As you said, using statements like FOR, but I don't have an in-depth understanding of this aspect. Of course, I have also read quite a few posts on this topic, and I really find it a bit deep, heh heh. Take it slow~~

re: willsort
First of all, thank you, moderator, for helping me many times. Regarding SET/A, this is how I understand and do it. Because when I get the date value, there is such a problem. For example, the order number is from the 1st to the 9th, but I have to get a 2-character value, otherwise it will be wrong when it comes to the even-numbered days. That is, for example, if it is the 7th, the value obtained is: 07. If the time I specified is entered as 7, then the two sides are not equal, and the statement will execute incorrectly. So I make the current date +0 to make it a ten-digit number to remove the space. Similarly, I have also processed the user-entered date to remove the ten-digit space, so that the statement can run smoothly.

Of course, I am very willing for the moderator to give a better solution.
I will try to take some time to add comments to the above (heh heh, I myself find it a bit confusing, if it weren't written by myself, I really wouldn't have the patience to read it)

PS: The World Cup is here, another torturous day~~~

[ Last edited by jastyg on 2006-6-9 at 21:40 ]
Floor 12 Posted 2006-06-09 11:32 ·  中国 江苏 镇江 电信
中级用户
★★
Credits 219
Posts 82
Joined 2005-10-29 10:56
20-year member
UID 44240
Status Offline
Regarding the verification of illegal characters, I came up with a method, but it feels a bit cumbersome. Let me post it first:

@echo off
set /p da=
for %%i in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,?,h,H,/?,/h,/H) do if "%da%"=="%%i" goto ok
goto warng
:ok
echo ok
goto exit
:warng
echo Error
:exit

This can indeed detect the date, but what about the verification of the time format?
Floor 13 Posted 2006-06-09 11:55 ·  中国 江苏 镇江 电信
中级用户
★★
Credits 219
Posts 82
Joined 2005-10-29 10:56
20-year member
UID 44240
Status Offline
For the detection of time, I thought of a stupid method
Check the user-entered time in segments for the same date.

I wonder if there is a better way?
Floor 14 Posted 2006-06-09 17:58 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re jastyg:

Understood the intention of the brother using set/a from the reply on floor 11, which is to remove the possible leading zeros in the date value to have a unified format for easy comparison.

Well, this problem can be viewed from two aspects:

1. Ensure all dates have possible leading zeros so that they can be compared. Because the system date usually has possible leading zeros, so we usually only need to handle the user-input date variable. The specific plan to be adopted is to pad first and then intercept, for example:

set today=%date:~8,2%
set /p day=Please enter the date:
set day=0%day%
set day=%day:~-2%
echo Input date: %day%; System date: %today%;

2. Ensure all dates do not have possible leading zeros so that they can also be compared. Because the system date usually has possible leading zeros, so we need to handle both the user-input date value and the system date value. Here we use the method of adding 10000 or 1000 first and then taking the remainder. For example

set today=%date:~8,2%
set /p day=Please enter the date:
set /a today=100%today% %% 100, day=100%day% %% 100
echo Input date: %day%; System date: %today%;
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 15 Posted 2006-06-09 19:14 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
The boss really has many ways, quite clever.

To jastyg:

Actually, there's no need to comment so much content. Too many comments will反而 have a sense of redundancy.

Moreover, when posting code, you can use this method to ensure that certain characters are not converted by the webpage and also facilitate others to copy your code for testing purposes: first input [code] and [/code], then paste the code between them, and then post it. Actually, it's quite simple. It's best to use the "Reply" mode to edit, as there are more formats available; the "Quick Reply to Topic" mode has almost no formats available. Those familiar with webpage code can manually input code here to edit. If you are not familiar, it is recommended to still use the "Reply" mode to do it.

[[i] Last edited by namejm on 2006-6-9 at 19:16 [/i]]
Forum Jump: