Proper Logic

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
booga73
Posts: 108
Joined: 30 Nov 2011 16:16

Proper Logic

#1 Post by booga73 » 17 Feb 2014 21:27

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

Cat
Posts: 32
Joined: 11 Nov 2011 12:04

Re: Proper Logic

#2 Post by Cat » 17 Feb 2014 21:59

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
)

booga73
Posts: 108
Joined: 30 Nov 2011 16:16

Re: Proper Logic

#3 Post by booga73 » 17 Feb 2014 22:12

Thank you Cat; :) i'm smacking myself in the face now .. . . .v/r Booga73

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Proper Logic

#4 Post by Squashman » 18 Feb 2014 07:59

You could also get rid of the FOR logic to capture the number and just redirect the FILE to a variable using SET /P.

Post Reply