Scoring in a batch file. Pass or Fail.
I recently had a situation where I had to write a little script to help a user determine if documents passed or failed a set of requirements based on user input. This is how I did it.
So – If/then statements are great and can allow you to get input, create variables based on environment settings, etc. This script is very simple and can be built upon to do a ton.
@ECHO OFF
set PF=PASS
set COUNTER=100
set /A COUNTER-=1
echo %Counter%
if %Counter% LEQ 97 set pf=fail
ECHO %PF%
pause
set /A COUNTER-=1
echo %Counter%
if %Counter% LEQ 97 set pf=fail
ECHO %PF%
pause
set /A COUNTER-=1
if %Counter% LEQ 97 set pf=fail
echo %Counter%
ECHO %PF%
pause
The above snippet of code does the following:
It initially sets the COUNTER to 100. “Set COUNTER=100”. This is our baseline and starting score and set the PF variable, by default to PASS. PF is short for Pass or Fail in this case. What the script does is add or subtract from that baseline and then check the adjusted baseline intermittently in-between those additions or subtractions looking to see if it LEQ (Less-than or equal too) a given number, in this case 97. The idea is – you could ask questions and based on the answers of the user add or subtract points arriving at a pass or fail ultimately.
By adding a few if/then or yes/no questions into the mix you could add or subtract points based on user input or check for system variables and do the same – and arrive at a pass or fail.
Some more info :
set /A COUNTER-=1 would SUBTRACT 1 from the COUNTER variable.
set /A COUNTER+=1 would ADD 1 to the COUNTER variable. The integer can change by any number provided, no just 1 so you wan add more weight to items.