Solved

Case or Switch statement

Posted on 2004-09-22
8
27,920 Views
Last Modified: 2008-01-09
Is there a case or switch statement in dos to use it in the batch file?

Thanks.
0
Comment
Question by:newuser11
  • 2
  • 2
8 Comments
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12128484
You mean like
Select case Var
Case 1
Case 2
Case Else
End Select
?

It depends on what what version of DOS you are referring to and what you need to accomplish.  If you are referring to the NT/2000/XP/2003, then IF is a fairly powerful command.

You would just need a seperate if statement for each with a goto at the end.

For example:

If "%var%" == "blue" (
Echo I'm doing blue
Blue command
Goto EndIf1
)
If "%var%" == "red" (
Echo I'm doing red
Red command
Goto EndIf1
)
If "%var%" == "green" (
Echo I'm doing green
Green Command
Goto EndIf1
)
:EndIf1
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12128491
For a switch command - if I understand you correctly:

If "%var%" == "Red" Set Var=Blue
0
 

Author Comment

by:newuser11
ID: 12129889
yes, you are right.  something like

Switch (Var)
Case Red:
         do something
Case Bule:
         do something
Default:
         do default

Thanks for your help.
0
 
LVL 9

Accepted Solution

by:
DrWarezz earned 50 total points
ID: 12133932
There isn't a switch/case statements that you can use in DOS. However, you can do the same thing basically, like so:

set var=Blue

if "%var%"=="Red" goto :Red
if "%var%"=="Blue" goto :Blue

:Default
REM  Put whatever you want to happen if none of the cases occur here.
goto :EOF

:Red
REM  In the case "Red", the program will jump to here.
goto :EOF

:Blue
REM  In the case "Blue", the program will jump to here.

:EOF


Hope that helps :)
[r.D]
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12394419
8-) ThanQ
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question