| 1. |
Solve : question about setting days to vars? |
|
Answer» Is it possable under xp to give give a user a prompt or window to allow them to select from a list of days. you might want to give them a menu instead yes I have got that but I wish to allow them to select any of the days they wish :example: Mondays Wednesdays and Fridays. I can not get this to work in a batch. I was hopefull that someone has done this in the past or knows of a way to allow user choice for more then one option at a time.why don't you ask for a yes/no answer for each day in turn? Quote from: DIAS de verano on May 20, 2008, 08:08:50 AM why don't you ask for a yes/no answer for each day in turn? This is still not working for me. Here is a section of the code that keeps giving me problems. Code: [Select]:LOOPZB CLS SET Choice= ECHO Do you want JK Defrag to run on Monday? ECHO Enter Yes or No SET /P Choice=Monday: ECHO %choice% |findstr /i /r "[n]" > NUL IF /I %errorlevel% EQU 0 SET mon=no && GOTO LoopZC ECHO %choice% |findstr /i /r "[y]" > NUL IF /I %errorlevel% EQU 0 SET mon=yes && GOTO LoopZC ECHO %choice% is not a valid choice ECHO please try agin ping -n 2 localhost > nul GOTO LoopZB :LoopZC CLS SET Choice= ECHO Do you want JK Defrag to run on Tuesday? ECHO Enter Yes or No SET /P Choice=Tuesday: ECHO %choice% |findstr /i /r "[n]" > NUL IF /I %errorlevel% EQU 0 SET tues=no && GOTO LoopZD ECHO %choice% |findstr /i /r "[y]" > NUL IF /I %errorlevel% EQU 0 SET tues=yes && GOTO LoopZD ECHO %choice% is not a valid choice ECHO please try agin ping -n 2 localhost > nul GOTO LoopZC :LoopZD CLS SET Choice= ECHO Do you want JK Defrag to run on Wednesday? ECHO Enter Yes or No SET /P Choice=Wednesday: ECHO %choice% |findstr /i /r "[n]" > NUL IF /I %errorlevel% EQU 0 SET wed=no && GOTO LoopZE ECHO %choice% |findstr /i /r "[y]" > NUL IF /I %errorlevel% EQU 0 SET Wed=yes && GOTO LoopZE ECHO %choice% is not a valid choice ECHO please try agin ping -n 2 localhost > nul GOTO LoopZD :LoopZE CLS SET Choice= ECHO Do you want JK Defrag to run on Thursday? ECHO Enter Yes or No SET /P Choice=Thursday: ECHO %choice% |findstr /i /r "[n]" > NUL IF /I %errorlevel% EQU 0 SET thurs=no && GOTO LoopZF ECHO %choice% |findstr /i /r "[y]" > NUL IF /I %errorlevel% EQU 0 SET thurs=yes && GOTO LoopZF ECHO %choice% is not a valid choice ECHO please try agin ping -n 2 localhost > nul GOTO LoopZE :LoopZF CLS SET Choice= ECHO Do you want JK Defrag to run on Friday? ECHO Enter Yes or No SET /P Choice=Friday: ECHO %choice% |findstr /i /r "[n]" > NUL IF /I %errorlevel% EQU 0 SET FRI=no && GOTO LoopZG ECHO %choice% |findstr /i /r "[y]" > NUL IF /I %errorlevel% EQU 0 SET fri=yes && GOTO LoopZG ECHO %choice% is not a valid choice ECHO please try agin ping -n 2 localhost > nul GOTO LoopZF :LoopZG ECHO you choose to run on: ECHO you choose to run on: >> "\\%computername%\C$\%homepath%\desktop\defrag.log" IF %mon% == yes ECHO Monday && SET day1=M IF %mon% == yes ECHO Monday >> "\\%computername%\C$\%homepath%\desktop\defrag.log" IF %tues% == yes ECHO Tuesday && SET day2=T IF %tues% == yes ECHO Tuesday >> "\\%computername%\C$\%homepath%\desktop\defrag.log" IF %wed% == yes ECHO Wednesday && SET day3=W IF %wed% == yes ECHO Wednesday >> "\\%computername%\C$\%homepath%\desktop\defrag.log" IF %thurs% == yes ECHO Thursday && SET day4=TH IF %thurs% == yes ECHO Thursday >> "\\%computername%\C$\%homepath%\desktop\defrag.log" IF %fri% == yes ECHO Friday && SET day5=F IF %fri% == yes ECHO Friday >> "\\%computername%\C$\%homepath%\desktop\defrag.log" Pause IF '%day1%' =='' (SET day2=T) ELSE IF NOT '%day2%' =='' SET day2=,T IF '%day1%' =='' && IF '%day2%' =='' (SET day3=W) ELSE IF NOT '%day3%' =='' SET day3=,W IF '%day1%' =='' && IF '%day2%' =='' && IF '%day3%' =='' (SET day4=TH) ELSE IF NOT '%day4%' =='' SET day4=,TH IF '%day1%' =='' && IF '%day2%' =='' && IF '%day3%' =='' && IF '%day4%' =='' (SET day5=F) ELSE IF NOT '%day5%' =='' SET day5=,F set day=%day1%%day2%%day3%%day4%%day5% Pause The batch fails just before the first pause if you do not choose yes to the Monday prompt. thanks again, WayneThat code looks way too complex and ambitious. Get the functioning right first and then add the error trapping. Code: [Select] @echo off :start REM get user input echo. set /p mon="Monday y/n ?" set /p tue="Tuesday y/n ?" set /p wed="Wednesday y/n ? set /p thu="Thursday y/n ?" set /p fri="Friday y/n ?" REM set up string with spaces between letters set string= if "%mon%"=="y" set string=M if "%tue%"=="y" set string=%string% T if "%wed%"=="y" set string=%string% W if "%thu%"=="y" set string=%string% TH if "%fri%"=="y" set string=%string% F REM remove any leading space if "%string:~0,1%"==" " set string=%string:~1,255% REM change each space to a comma and a space set string=%string: =, % echo. echo You chose these days %string% echo. set /p ok="Is this OK y/n ?" if "%ok%"=="n" goto start |
|