| 1. |
Solve : batch file not working help please? |
|
Answer» hi all i am making this batch file show some system commands and i cant get it to work hi i cant work out why if i put yes or no it does yes on bothYou need to check the errolevel. Not if they answered Y or N. Code: [Select]C:\Users\Squash>choice [Y,N]?Y C:\Users\Squash>echo %errorlevel% 1 C:\Users\Squash>choice [Y,N]?N C:\Users\Squash>echo %errorlevel% 2 thanks got it hi hi do i set a count down timer ?Quote from: sjolliffe2 on January 10, 2014, 04:04:37 PM hi hi do i set a count down timer ? Try choice /? and study the options. Or use 'timeout'. If you want only the number, put it in a 'for /f' loop.@sjolliffe2 writing like that can LEAD to spaghetti code if you not careful. This author recomends using "subroutines". you could also try using a programming language if your env allows you to . vbscrtip/powershell included.Quote from: briandams on January 10, 2014, 06:21:15 PM @sjolliffe2To avoid this you could put :1 and :2 into the if statement, but that can cause many more errors. As long as you format the white space properly and add APPROPRIATE comments you can avoid this. Often times looking back on my previous codes I get lost in the "function" based ones easier than in the linear "spaghetti" ones.I think that how hard something to READ is more based off how documented it is, because it's the documentation that explains how things work, and the purpose of certain parts of the code... Spaghetti code just means that you have to spend time following the individual "threads" of spaghetti loop around the line numbers... It's more unclean than it is unreadable, though documented spaghetti code is harder to read than documented subroutine oriented code.... but that is only because of the fact that you have to keep track of your spaghetti at the same time as the code itself. (And that is BORING.)Top-Down programming is the term they used way back, for code that starts and then progresses linearly. It's useful for a small project and is easier to read in small projects, IMO. |
|