?
Solved

Case or Switch statement

Posted on 2004-09-22
8
Medium Priority
?
29,387 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 200 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

762 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