Solved

Case or Switch statement

Posted on 2004-09-22
8
28,865 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
8 Comments
 
LVL 96

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 96

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 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