PDA

View Full Version : Batch File Selection Statement- If



heylin
05-05-2005, 09:33 AM
I am attempting to use an if statement so that if a user enters a 1 it opens a file but if they enter a 2 or a 3 it opens another file. Is this possible to do? I would have thought it so.

Does anyone has any idea or links that might help me find the answer?

Thanks in advance,


Peter

Brain Cell
05-05-2005, 09:38 AM
There's the CHOICE command , but its only suppported in Win95/98. If you're using 2000/XP then you might be able to download it and use it in your machine.

more info about CHOICE (http://www.google.com/search?sourceid=navclient&ie=UTF-8&rls=DVXA,DVXA:2004-49,DVXA:en&q=%22batch+files%22+choice)

for opening files you can use the START command (in case you were asking about that , too)

hope this is what you're looking for :)

nickname_changed
05-05-2005, 04:09 PM
Cheat and use the for command
for %answer in (1) do echo "option 1"
for %answer in (2) do echo "option 2"

A cool article on the For command:
http://weblogs.sqlteam.com/robv/articles/4099.aspx

Brain Cell
05-05-2005, 06:08 PM
or you can make a C\C++ program that with a switch statement then use system() to open files (i.e : system("start filename.extention");)

heylin
05-05-2005, 07:18 PM
for %answer in (1) do "Car safe crossing script.swf"
for %answer in (2) do "Cars Crashing on Bridge.swf"


This is what I tried for the for statement. It didn't work. Can anyone see where I may have gone wrong?

Thanks,

nickname_changed
05-05-2005, 09:36 PM
for %answer in (1) do "Car safe crossing script.swf"
for %answer in (2) do "Cars Crashing on Bridge.swf"


This is what I tried for the for statement. It didn't work. Can anyone see where I may have gone wrong?

Thanks,

You need to use the Start command like Brain Cell said.

for %answer in (1) do start "Car safe crossing script.swf"
for %answer in (2) do start "Cars Crashing on Bridge.swf"

Also I'm not 100% on the syntax - look it up.

nickname_changed
05-05-2005, 09:53 PM
On further inspecion I don't think it is possible with For. Do what Brain Cell said and write something in C/C++ (or if you want to finish it this year, maybe C#)

nickname_changed
05-05-2005, 09:56 PM
Hold on. Did you even try typing "If" into the console?

if %a == 1 (start someThing.swf) else (start anotherThing.swf)

Works on XPSP2 at least.

Salem
05-06-2005, 10:50 AM
Or just realise that cmd.exe, whilst a big improvement on command.com, is still fundamentally a broken shell incapable of anything but the most basic of tasks.