Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Nested If commands  (Read 3312 times)

0 Members and 1 Guest are viewing this topic.

chris sugg

  • Guest
Nested If commands
« on: October 07, 2004, 01:46:47 PM »
I have a .BAT program that for some reason, does not execute the commands like I expected.  The code:

IF %3== x GOTO x
IF %3== y GOTO y
IF %3== z GOTO z

GOTO ERRORMSG

:x
IF %4== BAI2CD
del Cx
COPY %2
CALL prog1
goto end

:y
IF %4== BAI2PD
del C:y
COPY %2
CALL prog
goto end

IF %4== BAI2XPD
del C:y
COPY %2
CALL prog
goto end

GOTO ERRORMSG

%3 is y but %4 is not BAI2PD but it is BAI2XPD but the program always goes to the errmsg.  

Thanks,
Chris

2k dummy

  • Guest
Re: Nested If commands
« Reply #1 on: October 07, 2004, 04:13:21 PM »
Neither of the first 3 IF statements equates to true. At least one of them MUST equate to true before it will branch to anything besides the error message. Maybe your IF statements are comparing apples to oranges.

chris again

  • Guest
Re: Nested If commands
« Reply #2 on: October 08, 2004, 07:19:49 AM »
Hi 2K Dummy

I understand now what you are saying but am having trouble placing the IF [NOT] check in my code.  Where should it go? I still need to check %4 before I decide what to do and I really do not want to have to create 8 .bat programs since at the moment %4 can have 8 different values.

Thanks,
Chris

MalikTous

  • Guest
Re: Nested If commands
« Reply #3 on: October 09, 2004, 05:28:46 PM »
IF condition task

must be on single line.

IF %3==x goto xlabel
Works, goes to xlabel if %3 is X

IF %3==x
goto xlabel

Goes to xlabel unconditionally, the IF line only sets ERRORLEVEL flag.