home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 67,722 of 68,980   
   JJ to Tom Del Rosso   
   Re: leading zero   
   07 Mar 21 19:43:51   
   
   From: jj4public@gmail.com   
      
   On Sat, 6 Mar 2021 22:19:37 -0500, Tom Del Rosso wrote:   
   > This is curious.   
   >   
   > set x=09   
   > set /a y=x   
   >   
   > results in the answer zero, but it should give the invalid number error.   
   >   
   > set /a y=%x%   
   > does give the expected error.   
   >   
   > BTW I like to use   
   > set /a y=(1%x%-100) ...*/-+...   
   > as a compact way to remove the zero.   
      
   Numbers with leading zero(es) are treated as Octal numbers. So, "8" and "9"   
   number are invalid Octal numbers.   
      
   When SET /A is used with variables only (i.e. no constant), it doesn't   
   display any error message when it encounters an error. Instead, it simply   
   set the ERRORLEVEL, then sets the result of the calculation to zero. i.e. a   
   silent error.   
      
   e.g. this causes an error.   
      
     set/a 08   
      
   This causes a silent error.   
      
     dir>nul   
     echo %errorlevel%   
     rem above should output: 0   
      
     set x=07   
     set/a x   
     rem above should output: 7   
     echo %errorlevel%   
     rem above should output: 0   
      
     set x=08   
     set/a x   
     rem above should output: 0   
     echo %errorlevel%   
     rem above should output non zero   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca