Computing.Net > Forums > Programming > If errorlevel goto label ??

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

If errorlevel goto label ??

Reply to Message Icon

Name: wonderingdude
Date: April 9, 2009 at 16:55:42 Pacific
OS: Windows Vista
Subcategory: Batch
Comment:

Hi.
I have a question, What is wrong with this script?

echo off
:start
choice /c yn
if errorlevel 1 goto :label1
if errorlevel 2 goto :label2
goto :start
:label1
echo you chose yes.
pause >nul
exit
:label2
echo you chose no.
pause >nul
exit

I cant get it to work! Please tell me what im doing
wrong. And the easiest way to fix it.

Thanks for any reply



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: April 9, 2009 at 18:45:19 Pacific
Reply:

"if errorlevel x command" means if the errorlevel is greater than or equal to x do command, so start from the highest number and work your way down:

if errorlevel 2 goto :label2
if errorlevel 1 goto :label1

Your choice command also doesn't look quite right, "choice /c:yn" vs "choice /c yn".


0

Response Number 2
Name: wonderingdude
Date: April 9, 2009 at 18:53:55 Pacific
Reply:

Ah, Thanks! Suppose it makes sense :D


0

Response Number 3
Name: Mechanix2Go
Date: April 9, 2009 at 23:11:44 Pacific
Reply:

You can save some typing and clutter.

=================
:: goto choice

@echo off & setLocal EnableDelayedExpansion

choice
goto :!errorlevel!

:1
echo here's 1 & goto :eof

:2
echo here's 2 & goto :eof


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

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


how can i make dis progra... Help with with a c++ proj...



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: If errorlevel goto label ??

BATCH: 'goto labels' inside curlys www.computing.net/answers/programming/batch-goto-labels-inside-curlys/16500.html

attn: IVO * goto :label in FOR www.computing.net/answers/programming/attn-ivo-goto-label-in-for/16505.html

Batch File Using ERRORLEVEL and IF www.computing.net/answers/programming/batch-file-using-errorlevel-and-if/15635.html