Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: multiplying in a batch  (Read 13363 times)

0 Members and 1 Guest are viewing this topic.

millergram

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Windows Vista
    multiplying in a batch
    « on: July 02, 2011, 01:36:35 PM »
    I search the site a little and found not much on this topic Tried some things and so far nothing has worked so:
    Code: [Select]
    @echo off
    title Batch Timer v1.00
    mode con: cols=50 lines=15
    :main
    echo.Welcome To Batch Timer
    set /p input=Minutes=
    set input=%input%*60
    timeout /t %input% /nobreak
    echo.Done
    Echo.Press Any Key To Continue!
    Pause>nul
    if what i have i'm trying to make a simple timer and can not
    the %input%*60 dosent work the way i want it to it comes out as
    1*60 and i get an error message saying not with in valid ranges
    Please Explain how to Fix

    Salmon Trout

    • Guest
    Re: multiplying in a batch
    « Reply #1 on: July 02, 2011, 02:03:04 PM »
    Please Explain how to Fix

    Use set /A to do Arithmetic




    millergram

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Windows Vista
      Re: multiplying in a batch
      « Reply #2 on: July 02, 2011, 02:13:19 PM »
      Use set /A to do Arithmetic
      Thank you Mister Fish Man you are very helpful as always
      Kudos to you

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: multiplying in a batch
      « Reply #3 on: July 02, 2011, 08:03:48 PM »
      Why do people keep making delay programs in Batch?
      A suitable delay program was written about twenty years ago.  ::)

      Salmon Trout

      • Guest
      Re: multiplying in a batch
      « Reply #4 on: July 03, 2011, 12:50:59 AM »
      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


      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: multiplying in a batch
      « Reply #5 on: July 03, 2011, 02:13:37 AM »
      Sorry, I was thinking  of the SLEEP program somebody wrote awhile back.  :-[

      Salmon Trout

      • Guest
      Re: multiplying in a batch
      « Reply #6 on: July 03, 2011, 02:34:11 AM »
      Sorry, I was thinking  of the SLEEP program somebody wrote awhile back.  :-[

      That is the one I prefer.

      millergram

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Windows Vista
        Re: multiplying in a batch
        « Reply #7 on: July 05, 2011, 04:51:19 PM »
        Why do people keep making delay programs in Batch?
        A suitable delay program was written about twenty years ago.  ::)
        ??? Im no Programer or anything like that so What is a Delay Program ???

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: multiplying in a batch
        « Reply #8 on: July 05, 2011, 05:28:51 PM »
        What is a Delay Program ???

        A Program that delays.
        I was trying to dereference Null Pointers before it was cool.

        carlsomo



          Rookie

          • Experience: Beginner
          • OS: Unknown
          Delay msecs in a batch file
          « Reply #9 on: July 06, 2011, 10:41:25 PM »
          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.

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: multiplying in a batch
          « Reply #10 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.

          One form of it is
          SLEEP milliseconds
          You hare to make in from the windows API stuff.

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: multiplying in a batch
          « Reply #11 on: July 07, 2011, 02:58:18 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.

          One form of it is
          SLEEP milliseconds
          You hare to make in from the windows API stuff.

          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)
          I was trying to dereference Null Pointers before it was cool.

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: multiplying in a batch
          « Reply #12 on: July 07, 2011, 01:58:17 PM »
          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.