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,067 of 68,980   
   JJ to All   
   How to thoroughly check if a variable co   
   25 Oct 17 20:36:39   
   
   From: jj4public@vfemail.net   
      
   e.g. if I try to check it like this:   
      
     @echo off   
     setlocal   
     call :check notAnumber   
     call :check 123   
     call :check 0   
     goto :eof   
     :check   
     set /a n=%1   
     if "%n%" equ "0" (echo FALSE) else (echo TRUE)   
      
   Only the first two checks shows the correct answer. The third one is   
   incorrect.   
      
   I've also found an answer in SO, but the code fails if the variable being   
   checked is empty or if the value is e.g. (no quotes) "12 34". i.e. shown as   
   TRUE, where it should have been FALSE.   
      
      
      
   While I could make it do a simple pre-check for an empty variable. e.g.   
      
     if not "%num%" == "" (   
       ::do interget check...   
     ) else (   
       echo FALSE   
     )   
      
   But it seems only to add complexity of the validation process.   
   So, is there a simpler method? Without using any external program.   
      
   --- 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