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

Author Topic: error while comparing two numbers  (Read 4434 times)

0 Members and 1 Guest are viewing this topic.

Yogesh123

    Topic Starter


    Beginner

    error while comparing two numbers
    « on: February 04, 2010, 03:14:43 AM »
    Dear Experts,
    I am comparing the time difference of current time with process log time,
    time Format is as follows,
    current time = 1526 (which is 03:26pm)
    landed process Log time is = 0945 (which is 09:45am)

    but i am getting following error,
    Invalid number. Numeric constants are either decimal (17),
    hexadecimal (0x11), or octal (021).


    please help!!!
    code:-
    ----
    @echo off
    cd\
    d:
    cd D:\Test_Setup
    call ProcessStartTime.vbs result of this in processtime.txt is - EXCEL.EXE 20100204094539.749966+330 2644
    for /f "tokens=1" %%i in (processtime.txt) do set Proc=%%i
    if %Proc% EQU EXCEL.EXE GOTO yy
    GOTO End
    :yy
    For /f "tokens=2" %%j in (processtime.txt) do set LTIME=%%j
    set LGTIME=%LTIME:~8,4%
    echo License acquired Time is %LGTIME%

    set Ct=%time%
    set Ch=%Ct:~0,2%
    set Cm=%Ct:~3,2%
    Set /a CTIME=%Ch%%Cm%
    echo Current Time is %CTIME%

    set /A TDiff=%CTIME%-%LGTIME%
    echo time differense is %TDiff%
    ------

    gpl



      Apprentice
    • Thanked: 27
      Re: error while comparing two numbers
      « Reply #1 on: February 04, 2010, 03:52:34 AM »
      The problem is that 0945 is deemed to be octal because it starts with a zero (I came across this some years ago with javascript) and 9 is not a valid octal digit

      However the difference value is nonsensical.

      As you have already used vbscript, I suggest that you write a quick time comparison script to work out the duration

      BillRichardson



        Intermediate

        Thanked: 15
        Re: error while comparing two numbers
        « Reply #2 on: February 04, 2010, 03:53:08 AM »
        set /?
        New switches have been added to the SET command:

            SET /A expression

        Must use set /a for number to be used to add or subtract.
          
        Bill Richardson

        Yogesh123

          Topic Starter


          Beginner

          Re: error while comparing two numbers
          « Reply #3 on: February 04, 2010, 04:14:36 AM »
          Dear BillRichardson,
          As suggested - I have tried this,
          changed the command to
                     set /a TDiff=%CTIME%-%LGTIME%
          but no change, still the same error is appearing,
          please assist,



          set /?
          New switches have been added to the SET command:

              SET /A expression

          Must use set /a for number to be used to add or subtract.
            

          Yogesh123

            Topic Starter


            Beginner

            Re: error while comparing two numbers
            « Reply #4 on: February 04, 2010, 04:17:56 AM »
            Dear gpl,
            Thanks for the quick reply,
            i am not aware of "quick time comparison script"
            how to do this?


            The problem is that 0945 is deemed to be octal because it starts with a zero (I came across this some years ago with javascript) and 9 is not a valid octal digit

            However the difference value is nonsensical.

            As you have already used vbscript, I suggest that you write a quick time comparison script to work out the duration

            gpl



              Apprentice
            • Thanked: 27
              Re: error while comparing two numbers
              « Reply #5 on: February 04, 2010, 05:22:19 AM »
              see this brilliant thread - http://www.computerhope.com/forum/index.php?topic=97758.0

              You would want something like

              Code: [Select]
              REM set test values
              set ctime=0545
              set lgtime=1533


              Rem calculate time difference in minutes

              echo Wscript.echo eval(WScript.Arguments(0))>evaluate.vbs

              set vbstring=(timeserial(%lgtime:~0,2%,%lgtime:~-2%,0) - timeserial(%ctime:~0,2%,%ctime:~-2%,0)) * 1440

              for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "%vbstring%" ' ) do set Duration=%%A

              del evaluate.vbs

              Echo %Duration%

              Salmon Trout

              • Guest
              Re: error while comparing two numbers
              « Reply #6 on: February 04, 2010, 03:47:32 PM »
              I agree that VBscript is more convenient in many ways for processing time & date data but I cannot resist mentioning a couple of things...

              If you are processing strings which might have a leading zero & you want to do arithmetic you can carry out some preliminary tests & preventive measures

              Suppose %hhmm% is a 4 digit string representing time.

              set hh=%hhmm:~0,2% will isolate the first 2 characters, as we know...

              and

              set mm=%hhmm:~2,2% will isolate the second pair of characters

              Test if the first char of each string is a zero and if it is, chop it off...

              if "%hh:~0,1%"=="0" set hh=%hh:~1%
              if "%mm:~0,1%"=="0" set mm=%mm:~1%


              Now you have an hour between 0 and 23 and a minute between 0 and 59.

              Now you can safely do arithmetic with set /a

              set /a minutes=(60*%hh%)+%mm%





              BillRichardson



                Intermediate

                Thanked: 15
                Re: error while comparing two numbers
                « Reply #7 on: February 05, 2010, 05:44:53 PM »
                Code: [Select]
                @echo off

                Set /a DirSize=1307791263

                echo DirSize = %DirSize%
                Set /a AvSpace=1254895616
                echo  AvSpace = %AvSpace%

                set /a diff = %DirSize% - %AvSpace%

                echo diff = %diff%


                If %DirSize% gtr %AvSpace% GoTo TooLarge

                :TooLarge
                echo Too Large

                Output:


                C:\> comnumbers.bat
                DirSize = 1307791263
                 AvSpace = 1254895616
                diff = 52895647
                Too Large

                C:\>

                _____________________________
                p.s
                The compare op may be one of:

                    EQU - equal
                    NEQ - not equal
                    LSS - less than
                    LEQ - less than or equal
                    GTR - greater than
                    GEQ - greater than or equal

                and the /I switch, if specified, says to do case insensitive string
                compares.  The /I switch can also be used on the string1==string2 form
                of IF.  These comparisons are generic, in that if both string1 and
                string2 are both comprised of all numeric digits, then the strings are
                converted to numbers
                and a numeric comparison is performed.
                Bill Richardson

                Helpmeh



                  Guru

                • Roar.
                • Thanked: 123
                  • Yes
                  • Yes
                • Computer: Specs
                • Experience: Familiar
                • OS: Windows 8
                Re: error while comparing two numbers
                « Reply #8 on: February 05, 2010, 05:48:05 PM »
                Just pointing this out. You don't need the /a switch in the set command unless you are doing arithmetic.
                Where's MagicSpeed?
                Quote from: 'matt'
                He's playing a game called IRL. Great graphics, *censored* gameplay.

                BillRichardson



                  Intermediate

                  Thanked: 15
                  Re: error while comparing two numbers
                  « Reply #9 on: February 05, 2010, 06:02:01 PM »
                  Just pointing this out. You don't need the /a switch in the set command unless you are doing arithmetic.

                  Thanks, your are right.   

                  The set /a  does not seem hurt to with a compare operation.  The conversion to numbers is automatic but a set /a does not hurt.  Also, the  command interpreter, is sometimes confused when a string starts with 014790. The Command interpreter believes the number is octal.

                  p.s.  Floating point is a problem also for the Command interpreter.
                  Bill Richardson