-1

This is my first question so sorry if its a litle vague.

I have been working on a program for a wile now, it is supposed to be a schedule of tasks and the time those tasks have to be completed.

Everything works just fine but i cant figure out why this part doesn't work.

:edit              
echo Select Task         
echo (from 1 to 7)              
set /p sel=  
if %sel%=1 ( goto task1 ) 

And then its supposed to bring me here

:task1           
pause                                
echo Insert Task           
echo.         
set /p task1=        
echo.             
echo Set Time          
echo.    
set /p %time1%=         
echo.             
pause  
npocmaka
  • 55,367
  • 18
  • 148
  • 187
Faih Faih
  • 35
  • 4
  • Open a command prompt window and run `if /?` to get displayed the help for this command. As you can read the equal operator is `==` and not `=` or `EQU`. Also when you run your batch file from within a command prompt window after using command __CD__ to change to the directory of the batch file and executing it by entering its name and pressing RETURN, you can see the error messages output by Windows command interpreter on syntax errors like this one. Double clicking on a batch file is not good for testing a batch file in development as console window is automatically closed on execution exit. – Mofi May 02 '17 at 14:44
  • See also at least first chapter of answer [Batch file comparison of variable with constant fails](http://stackoverflow.com/a/42448601/3074564) which is about __Debugging a batch file__. – Mofi May 02 '17 at 14:46
  • You will find [SS64's Batch Reference Site](https://ss64.com/nt/) to be useful. – Jeff Zeitlin May 02 '17 at 14:53
  • `set /p %time1%=` is most likely also wrong. This line assigns the string entered by the user (if entered anything at all) to the environment variable with the name as environment variable `time1` has currently assigned. I suppose this line is executed as `set /p =` which is again a syntax error because of `time1` is not defined at this point on batch execution. You need most likely `set /P "time1=Set time: "` and hope that the batch user really enters what you expect. – Mofi May 02 '17 at 14:55
  • I'm flagging this question because questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example. –  May 03 '17 at 01:48

3 Answers3

2

As @Antonio said, there is a problem with the if statement. I also find another problem in :task1

set /p %time1%=

should be

set /p time1=

...and go to www.ss64.com/nt and take a little lesson of batch scripting.

2

It's your IF statement. a single equals sign "=" is used as an assignment operator in batch:

set var=fubar

to compare two values use a double equals "==":

if "%var%"=="fubar" echo It'll be reet!

Hope that helps, this was one of the things that always got me when I was starting to code and you will get used to it.

Matt
  • 74,352
  • 26
  • 153
  • 180
Sitri
  • 471
  • 4
  • 3
1

The line: if %sel%=1 ( goto task1 ) is very incomplete;

Write it so:

if "%sel%"=="1" goto task1
Matt
  • 74,352
  • 26
  • 153
  • 180
Antonio Gschossmann
  • 532
  • 1
  • 7
  • 18