Set /p coding problems on XP - habeascorpus - 03-09-2010
I'm trying to create a batch program that gives a choice (Y/N or 1/2) and if Y (or 1) is input by the user It would run a program already on my computer. I've searched all I can but most things don't work (or I don't understand them). The one I'm currently using is gutted and adapted from the only working one I found but no matter what I try something goes wrong and it loops to the beginning without executing my program. Here's the code
Code: @echo off
CLS
:LOOP
SET userInput=
SET /P userInput=So, Y or N?
:: check userInput
IF "%userInput%"=="" GOTO 3
:: /I makes the IF comparison case-insensitive
IF /I "%userInput%"=="Y" GOTO 1
IF /I "%userInput%"=="Y" GOTO 2
echo %userInput%
GOTO Again
:3
echo.
echo ERROR:Enter the message or type exit and press Enter.
GOTO Again
:1
echo good
CALL matrix.bat
pause
:2
GOTO Again
:Again
PAUSE
CLS
GOTO Loop
:End
When executed following is the output
======================================
SM:\ User Input Line
Input was unexpected at this time.
D:\SM>
I have very little clue as with what I should be fiddling...
By the way, the program is called matrix.bat and I'm running XP so choice doesn't work. I want it to read user input and would be grateful for any help on the matter.
RE: Set /p coding problems on XP - TheWiz - 04-02-2010
You did not correctly initialize the userinput method. You must verify to the program that you want to use wither numbers or letters as your choice. The choice command is better suited for yes or no, so here is a model for the set command that could actually be edited to suit either letters or numbers.
Code: @echo offSet /P _dept=Please enter Department:If "%_dept%"=="" goto :sub_errorIf /i "%_dept%"=="finance" goto sub_financeIf /i "%_dept%"=="hr" goto sub_hr
goto:eof
:sub_finance
echo You chose the finance dept
goto:eof
:sub_hr
echo You chose the hr dept
TheWiz
RE: Set /p coding problems on XP - habeascorpus - 04-07-2010
Lol, i actually found that one already but scrapped it for ine reason or another (Something didn't work I think). Also what you, most others, and myself-at the time- failed to notice that made my current set up not work is here:
Code: :: /I makes the IF comparison case-insensitive
IF /I "%userInput%"=="Y" GOTO 1
IF /I "%userInput%"=="Y" GOTO 2
so input "y" tells the program to continue but also close, not knowing what to do, it closes. Pretty simple but the bunch of people (I've posted this on other sites as well) that saw it missed it.
I got it working a little while ago and revamped it to serve as a pretty cool program to open websites, Microsoft Office Apps, and even my class notes. It won't work (only the Office Apps really, depending on what version you have, mine is 2003. You need to find your own notes/files paths' on your own) without some personalized touches but the code is kinda fun.
Code: @echo off
COLOR 37
:0
CLS
TITLE Internet Shortcuts
ECHO Latin/Google/Calender/Games/Office/Notes/exit
SET /P userInput=
:: check userInput
IF "%userInput%"=="exit" GOTO 6
:: /I makes the IF comparison case-insensitive
IF /I "%userInput%"=="Latin" GOTO 1
IF /I "%userInput%"=="Google" GOTO 2
IF /I "%userInput%"=="Calender" GOTO 3
IF /I "%userInput%"=="Games" GOTO 4
IF /I "%userInput%"=="Limbo" GOTO 5
IF /I "%userInput%"=="Office" GOTO 7
IF /I "%userInput%"=="Notes" GOTO 12
IF /I "&userInput%"=="" GOTO 16
echo %userInput%
:16
GOTO 0
:1
START http://archives.nd.edu/words.html
goto exit
:2
START www.google.com
goto exit
:4
START www.onemorelevel.com
goto exit
:5
START www.computerlimbo.com
goto exit
:6
exit
:7
CLS
TITLE Microsoft Office Shortcuts
ECHO Word/Power Point/Publisher/Excel/Notes/Back
SET /P userInput=
IF "%userInput%"=="exit" GOTO 6
IF /I "%userInput%"=="Back" GOTO 0
IF /I "%userInput%"=="Word" GOTO 8
IF /I "%userInput%"=="Power Point" GOTO 9
IF /I "%userInput%"=="Publisher" GOTO 10
IF /I "%userInput%"=="Excel" GOTO 11
IF /I "%userInput%"=="Notes" GOTO 12
echo %userInput%
:17
GOTO 7
:8
cd\
cd program files\microsoft office
IF EXIST OFFICE11 CD OFFICE11
start WINWORD.exe
exit
:9
cd\
cd program files\microsoft office
IF EXIST OFFICE11 CD OFFICE11
start POWERPNT.exe
exit
:10
cd\
cd program files\microsoft office
IF EXIST OFFICE11 CD OFFICE11
START MSPUB.exe
exit
:11
cd\
cd program files\microsoft office
IF EXIST OFFICE11 CD OFFICE11
START EXCEL.exe
exit
:12
CLS
TITLE Course Notes
ECHO RELIGION/APWH/MUSIC/Back/Goto Start
SET /P userInput=
IF "%userInput%"=="exit" GOTO 6
IF /I "%userInput%"=="Back" GOTO 7
IF /I "%userInput%"=="Goto start" GOTO 0
IF /I "%userInput%"=="Religion" GOTO 13
IF /I "%userInput%"=="APWH" GOTO 14
IF /I "%userInput%"=="Music" GOTO 15
echo %userInput%
:18
GOTO 12
:13
CD\
CD documents and settings
CD %userprofile%
CD my documents
cd religion
start notes.doc
exit
:14
CD\
CD documents and settings
CD %userprofile%
CD my documents
CD APWH
start notes1.doc
exit
:15
CD\
CD documents and settings
CD %userprofile%
CD my documents
CD music
start notes.doc
exit
|