Page 1 of 1

Proper Logic

Posted: 17 Feb 2014 21:27
by booga73
for the likes of me :shock: , I can't seem to get this "basic" logical to compare values; how can it verify correctly the If condition?

If %MyBit% does have the value 100 then %var1% should be echoed to GBitLockIP.txt but instead the value is being written to BBitLockIP.txt.

If %MyBit% does have the value less than 100 then %var1% should be echoed to BBitLockIP.txt but I instead see the value is being written to GBitLockIP.txt.

Please, what's the proper logic?

Code: Select all

@ECHO OFF

set var1=192.168.1.1
set /a GoodBit=100

rem c:\temp1a\tmp1.txt has a single line which is a number from 0 to 100, i.e. 100% is current value.

for /f "tokens=1 delims=%%" %%b in (c:\temp1a\tmp1.txt) do set /a MyBit=%%b

rem this echo statement shows on screen the correct value extracted from tmp1.txt.
echo MyValue: %MyBit%

If "%MyBit%" EQU "GoodBit" echo %var1% >> C:\temp1a\GBitLockIP.txt
If "%MyBit%" NEQ "GoodBit" echo %var1% >> c:\temp1a\BBitLockIP.txt



thank you for the valued support.
v/r Booga73

Re: Proper Logic

Posted: 17 Feb 2014 21:59
by Cat
Quotes around your variables aren't usually needed, but it looks like just missing percents around 'GoodBit' cause the if statement to fail:

Code: Select all

@echo off

set var1=192.168.1.1
set /a GoodBit=100

for /f "tokens=1 delims=%%" %%b in (c:\temp1a\tmp1.txt) do set /a MyBit=%%b

echo MyValue: %MyBit%

If %MyBit% EQU %GoodBit% (
   echo %var1% >> C:\temp1a\GBitLockIP.txt
) else (
   echo %var1% >> c:\temp1a\BBitLockIP.txt
)

Re: Proper Logic

Posted: 17 Feb 2014 22:12
by booga73
Thank you Cat; :) i'm smacking myself in the face now .. . . .v/r Booga73

Re: Proper Logic

Posted: 18 Feb 2014 07:59
by Squashman
You could also get rid of the FOR logic to capture the number and just redirect the FILE to a variable using SET /P.