Solved

Case or Switch statement

Posted on 2004-09-22
8
28,515 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

740 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