Solved

Case or Switch statement

Posted on 2004-09-22
8
26,781 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now