Saved Bookmarks
| 1. |
Solve : multiplying in a batch? |
|
Answer» I search the site a little and found not much on this topic Tried some things and so FAR nothing has WORKED so: Please Explain how to Fix Use set /A to do Arithmetic Quote from: Salmon Trout on July 02, 2011, 02:03:04 PM Use set /A to do ArithmeticThank you Mister Fish Man you are very helpful as always Kudos to youWhy do people keep making delay programs in Batch? A suitable delay program was written about twenty years ago. It isn't a "delay program in batch". It's a batch script which asks the user for a number which represents a desired delay measured in minutes. The script then multiplies that number by sixty and supplies it to a Windows program, timeout.exe, which pauses execution for a time which needs to be supplied as a number of seconds. Code: [Select]C:\>timeout /? TIMEOUT [/T] timeout [/NOBREAK] Description: This utility accepts a timeout parameter to wait for the specified time period (in seconds) or until any key is pressed. It also accepts a parameter to ignore the key press. Parameter List: /T timeout Specifies the number of seconds to wait. Valid range is -1 to 99999 seconds. /NOBREAK Ignore key presses and wait specified time. /? Displays this help message. NOTE: A timeout value of -1 means to wait indefinitely for a key press. Examples: TIMEOUT /? TIMEOUT /T 10 TIMEOUT /T 300 /NOBREAK TIMEOUT /T -1 Sorry, I was thinking of the SLEEP program somebody wrote awhile back. Quote from: Geek-9pm on July 03, 2011, 02:13:37 AM Sorry, I was thinking of the SLEEP program somebody wrote awhile back. That is the one I prefer. Quote from: Geek-9pm on July 02, 2011, 08:03:48 PM Why do people keep making delay programs in Batch?Im no Programer or anything like that so What is a Delay Program Quote from: millergram on July 05, 2011, 04:51:19 PM What is a Delay Program A Program that delays.Most delay programs written in batch use ping to the reply back address: PING 127.0.0.1 -n 6 for a 5 seconds delay. Here is a delay batch that always delays to within 1/100 secs regardless of machine: Code: [Select]@echo off&goto :start :Delay milliseconds echo.Delay milliseconds echo.Delays for the specified # of milliseconds echo.Always accurate to within 10 milliseconds echo.Returns error of precision in milliseconds exit /b 1 :start if [%1]==[] goto :Delay Syntax if /i %1 geq 600000 goto :Delay Syntax setlocal enableextensions set correct=0 set /a msecs=%1+5 if /i %msecs% leq 20 set /a correct-=2 set time1=%time: =% set /a tsecs=%1/1000 2>nul set /a msecs=(%msecs% %% 1000)/10 for /f "tokens=1-4 delims=:." %%a in ("%time1%") do ( set hour1=%%a&set min1=%%b&set sec1=%%c&set "mil1=%%d" ) if /i %min1:~0,1% equ 0 set min1=%min1:~1% if /i %sec1:~0,1% equ 0 set sec1=%sec1:~1% if /i %mil1:~0,1% equ 0 set mil1=%mil1:~1% set /a sec1+=(%hour1%*3600)+(%min1%*60) set /a msecs+=%mil1% set /a tsecs+=(%sec1%+%msecs%/100) set /a msecs=%msecs% %% 100 ::check for midnight crossing if /i %tsecs% geq 86400 set /a tsecs-=86400 set /a hour2=%tsecs% / 3600 set /a min2=(%tsecs%-(%hour2%*3600)) / 60 set /a sec2=(%tsecs%-(%hour2%*3600)) %% 60 set /a err=%msecs% if /i %msecs% neq 0 set /a msecs+=%correct% if /i 1%msecs% lss 20 set msecs=0%msecs% if /i 1%min2% lss 20 set min2=0%min2% if /i 1%sec2% lss 20 set sec2=0%sec2% set time2=%hour2%:%min2%:%sec2%.%msecs% :wait set timen=%time: =% if /i %timen% geq %time2% goto :end goto :wait :end for /f "tokens=2 delims=." %%a in ("%timen%") do set NUM=%%a if /i %num:~0,1% equ 0 set num=%num:~1% set /a err=(%num%-%err%)*10 endlocal&exit /b %err% This is helpful if timing is critical or if one wishes to measure the code execution time for a project the code is similar.Somewhere there is a delay or sleep program in the old NT stuff. In my personal stuff I have something hat came out of then-old Borderland Pascal library. Sorry, I can't find a version of it except for the one in my stuff. I don't thin they will let me attach it here. They are afraid of virus. One form of it is SLEEP milliseconds You hare to make in from the windows API stuff.Quote from: Geek-9pm on July 07, 2011, 02:13:37 AM Somewhere there is a delay or sleep program in the old NT stuff. In my personal stuff I have something hat came out of then-old Borderland Pascal library. Sorry, I can't find a version of it except for the one in my stuff. I don't thin they will let me attach it here. They are afraid of virus. Code: [Select]#define WIN32_LEAN_AND_MEAN #include <windows.h> int main (int argc, char *argv[]) { int convert=0; if(argc==1) { printf("enter number of ms to sleep.\n"); return 0; } convert=atoi(argv[1]); Sleep(convert); return 1; } Or, In Pascal (FreePascal, to be specific): Code: [Select]program Wait; uses sysutils; var SleepAmount:Integer; StrParam:String; Code:Integer; begin if ParamCount >=1 then begin StrParam :=ParamStr(1); Val(StrParam,SleepAmount,Code); Sleep(SleepAmount); exit(); end; writeln('Usage: Sleep <milliseconds>'); end. etc. Implementing something akin to "sleep" is pretty trivial, regardless of the language, or platform. (the above FreePascal example compiles and works on linux, for example) Also: Quote In my personal stuff I have something hat came out of then-old Borderland Pascal library.If it was a Pascal program (that you compiled) it might not work because it's 16-bit, but also, if it used the crt module it would crash on startup with a divide overflow (or a similar error) on anything newer than about a 486. (This of course would go for any "example" .pas files) Thank you BC. Stuck my foot in mouth again. Yes, it is so trivial, yet some many people want to rite it in a batch file. Somebody shroud compile a short, sweet win32 EXE that will count in tenths of a second or break from the keyboard. Using the system timer, I believe, is only useful down to 55 milliseconds. I used that years ago in a telecom program written in QBASIC. As I recall, Borland had a micro timer that nursed the hardware for very short time events. |
|