Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a Variable In a Batch File

Status
Not open for further replies.

tekdudedude

Technical User
Sep 29, 2007
79
Hello,

I need to reset the value of a variable based on an if condition. It does not seem that a set statement works within an IF clause.

Example
Code:
@echo off
set VAR=1
if "%XFER%" == "1" (
   set VAR=2
)

echo %VAR%
The above will output the value 1, i.e. as if the set statement in the IF clause did not exist.

What can you recommend?

Thanks,

TD
 
>> Trick question right? You are setting VAR but testing for XFER.

Oop thanks for pointing that out (mistake).
Code:
@echo off
set VAR=1
if "%VAR%" == "1" (
   set VAR=2
)

echo %VAR%

Problem still exists as far as I have tested. Type was in my example.

Any suggestions?

Thanks again,

TD
 
The code you last posted works fine for me....

"We must fall back upon the old axiom that when all other contingencies fail, whatever remains, however improbable, must be the truth." - Sherlock Holmes

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top