Computing.Net > Forums > Programming > Batch File Using ERRORLEVEL and IF

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File Using ERRORLEVEL and IF

Reply to Message Icon

Name: dwagner
Date: August 8, 2007 at 09:53:29 Pacific
OS: Windows XP SP2
CPU/Ram: Pentium M 1.73 GHz. 512 M
Product: Radiant Systems
Comment:

I am trying to make a batch file to run a different set of commands depending on a the location of the office they're in. I'd like to have the user tell the system where they are and then have the system to go a series of commands based on their answer. I have the following started;

@ ECHO OFF
ECHO Select your office from the list...
ECHO 1.WEATHERFORD
ECHO 2.DALLAS
ECHO 3.FT.WORTH

START C:\WINDOWS\SYSTEM32\CHOICE.exe /C:123

IF ERRORLEVEL 1 GOTO WEATHERFORD
IF ERRORLEVEL 2 GOTO DALLAS
IF ERRORLEVEL 3 GOTO FTW

:WEATHERFORD
ECHO YOU ARE IN WEATHERFORD
PAUSE
GOTO END


:DALLAS
ECHO YOU ARE IN DALLAS
PAUSE
GOTO END

:FTW
ECHO YOU ARE IN FT. WORTH
PAUSE
GOTO END

:END
ECHO VAYA CON DIOS
PAUSE

However, no matter what is input, it always says 'You are in Weatherford'. Can anyone help me with this?!?!?! I would be incredibly grateful!!!


Dan W.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: August 8, 2007 at 10:47:42 Pacific
Reply:

IF ERRORLEVEL 1

means 1 *OR MORE* so you always wind up on weatherford.

::==better
@echo off
setLocal EnableDelayedExpansion

ECHO Select your office from the list...
ECHO 1.WEATHERFORD
ECHO 2.DALLAS
ECHO 3.FT.WORTH

CHOICE /C:123

goto %ERRORLEVEL%

:1
ECHO YOU ARE IN WEATHERFORD
PAUSE
GOTO END


:2
ECHO YOU ARE IN DALLAS
PAUSE
GOTO END

:3
ECHO YOU ARE IN FT. WORTH
PAUSE
GOTO END

:END
ECHO VAYA CON DIOS
PAUSE
::==


=====================================
If at first you don't succeed, you're about average.

M2



0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File Using ERRORLEVEL and IF

Batch file to start and stop servic www.computing.net/answers/programming/batch-file-to-start-and-stop-servic/15882.html

batch file name date and time www.computing.net/answers/programming/batch-file-name-date-and-time/15060.html

Batch File Deletion Help www.computing.net/answers/programming/batch-file-deletion-help/18983.html