Problem with batch comparisons

Asked

Viewed 50 times

0

Good afternoon. I was making a simple batch file, in general, a friend of mine needed me to do that puzzle of 3 gallons of batch water (8, 5 and 3 liter gallons) In general the batch logic is very simple, but it is with a problem in comparison, where there is the line:

set /A VARIAVELVASO3NO1=%CONTEUDOVASO3%-%QUANTIDADELIVREVASO1%+10
if "%VARIAVELVASO3NO1%" GEQ "10" (
    set/a CONTEUDOVASO3=%CONTEUDOVASO3%-%QUANTIDADELIVREVASO1%
    set/a CONTEUDOVASO1=8
    goto JOGOVASOS
) ELSE (
    set/a CONTEUDOVASO1=%CONTEUDOVASO3%+%CONTEUDOVASO1%
    set/a CONTEUDOVASO3=0
    goto JOGOVASOS
)

The value %VARIAVELVASO3NO1% is 8, since %CONTEUDOVASO3% is 3; and %QUANTIDADELIVREVASO1% is 5 (3-5+10=8). However, instead of entering the FALSE state (which would be the ELSE) he enters the first, which is the TRUE state, I first thought it was a problem with negative numbers, so I put everything above 10 (so the +10 in the formula) but still the problem persists, any idea what it might be?

  • Have you tried without the quotation marks? if %VARIAVELVASO3NO1% GEQ 10 (

  • That’s all, I can’t believe I spent an hour trying to solve the two-quote problem, thank you very much man!

  • Can you accept the answer below then? Thanks!

2 answers

1


Remove the quotation marks:

if %VARIAVELVASO3NO1% GEQ 10 (
    set/a CONTEUDOVASO3=%CONTEUDOVASO3%-%QUANTIDADELIVREVASO1%
    set/a CONTEUDOVASO1=8
    goto JOGOVASOS
)

1

Darius of the coast, always recommend to make comparisons quote-free

only make quotes comparisons when comparing strings with several words.

and do it this way:

    if "%string1%" equ "%string2" (Echo.São iguais) Else (
    Echo.Não são iguais
    )

tip.

  • Yes, I had already realized the mistake, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.