Batch File IF less then mystery

January 2, 2010 at 21:40:34
Specs: Windows Vista

I'm writing a rpg batch file, but i can't get a certain command to work.

I'm trying to get it so that the user is able to purchase an item if they have enough money, but can't if they dont.

simple, right? I tried using two 'if' attempts, but neither worked.

please look over both, and see if you can help...

ATTEMPT ONE (if '%$money%' GEQ '10000')

if '%input%'=='1' (
if '%$money%' GEQ '10000' (
set /a $money=%$money%-10000
set $ob-shla=Yes
if not '%$money%' GEQ '10000' goto shop-nomoney
goto stuffcheck

ATTEMPT TWO (if '%$money%' LSS '0')

set curbalance=%$money%

if '%input%'=='1' (
set chosobj=ob-shla
set /a $money=%$money%-10000
set $ob-shla=Yes
goto shop-pricecheck

if '%$money%' lss '0' (
set $money=%curbalance%
set $%chosobj%=No
goto shop-nomoney
goto shopscreen

See More: Batch File IF less then mystery

January 3, 2010 at 05:30:22
The single quotes make it a string comparison, and "-" comes before "0" in the ASCII table.

Report •

January 3, 2010 at 14:26:12
Am I wrong, but the "IF /?" definition is not correct ...

I acknowledge the fact that this happens:

C:\>if '-6' geq '-4' echo -6 is bigger than -4
-6 is bigger than -4

C:\>if -6 geq -4 echo -6 is bigger than -4


But it is not inline with this, cause they keep referring to it as a string:

If Command Extensions are enabled IF changes as follows:

IF [/I] string1 compare-op string2 command
IF CMDEXTVERSION number command
IF DEFINED variable command

where compare-op may be one of:

EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal

and the /I switch, if specified, says to do case insensitive string
compares. The /I switch can also be used on the string1==string2 form
of IF. These comparisons are generic, in that if both string1 and
string2 are both comprised of all numeric digits, then the strings are
converted to numbers and a numeric comparison is performed.

-4 is not a numeric digit ? Is it ?

Report •

January 3, 2010 at 18:23:16
-4 is a numeric digit.
'-4' is a string.

Report •

Related Solutions

January 4, 2010 at 02:40:27
I know that ...

C:\>if '6' geq '4' echo 6 is bigger than 4
6 is bigger than 4

C:\>if 6 geq 4 echo 6 is bigger than 4
6 is bigger than 4


You see it behave different, if I remove all of the minus signs. In this example, he comes to the same conclusion, which means both commands are treated the same way. This is as expected.

But in response 2, both commands behave differently, because he makes mistake thinking that the minus sign is part of a string.

Report •

January 4, 2010 at 12:58:28
tvc, I'm not sure if you're agreeing with me or not. In any case, reflect on the following:
E:\>if '10' gtr '4' @echo Y

Mon 01/04/2010

Report •

Ask Question