Saved Bookmarks
| 1. |
Solve : 10 seen as 1? |
|
Answer» HEY all, I've got a loop that runs a installation app on remote machines. I've set it out like this; Code: [Select]set count=1 :loop if /i %count% EQU 1 (set pc=nameofpc) if /i %count% EQU 2 (set pc=nameofpc) if /i %count% EQU 3 (set pc=nameofpc) if /i %count% EQU 4 (set pc=nameofpc) if /i %count% EQU 5 (set pc=nameofpc) if /i %count% EQU 6 (set pc=nameofpc) if /i %count% EQU 7 (set pc=nameofpc) if /i %count% EQU 8 (set pc=nameofpc) if /i %count% EQU 9 (set pc=nameofpc) if /i %count% EQU 10 (goto end) net use \\%pc% installation code here.... set /a count +=1 goto loop :end script complete exit my issue is that when count reaches 10 the if statement only See's it as 1, so instead of going to :end to redoes the first PC again. I've changed the numbers so they read 0-9 so it works, but I'd like to add another PC to it and I'm a little LOST as to why it is happening. NOTE; I have also tried putting " " around the number but that hasn't helped. any ideas???Seems %count% always has a value of 1 as it's never updated. The line "set /a count =+1" maybe should read "set /a count=%count%+1" Thanks for the reply. %count% ADDS an extra 1 every time passes 'set /a count +=1' fine. (i have added an 'echo %count% just before it trys to map to the PC, so I know which one it is doing) The problem is that after it gets to 9, it adds another one (becomes 10) but the 'if' statement fails to see it as 10 and See's it as 1 so it does the first PC again. As i said, I have changed the numbers to read 0-9 so that this isn't an issue at the mo and it works fine. But I'm going to have to add another PC withing the next few days so I'm trying to find an answer!!!!Sorry, I was wrong, but I have been unable to replicate your problem, there's just gotta be something else. I butchered your coding slightly as below and it runs without hitch. No problem with the IF statements picking up numbers >9. Code: [Select]set count=1 :loop if /i %count% EQU 1 (set pc=nameofpc) & echo %count% if /i %count% EQU 2 (set pc=nameofpc) & echo %count% if /i %count% EQU 3 (set pc=nameofpc) & echo %count% if /i %count% EQU 4 (set pc=nameofpc) & echo %count% if /i %count% EQU 5 (set pc=nameofpc) & echo %count% if /i %count% EQU 6 (set pc=nameofpc) & echo %count% if /i %count% EQU 7 (set pc=nameofpc) & echo %count% if /i %count% EQU 8 (set pc=nameofpc) & echo %count% if /i %count% EQU 9 (set pc=nameofpc) & echo %count% if /i %count% EQU 10 (set pc=nameofpc) & echo %count% if /i %count% EQU 11 (set pc=nameofpc) & echo %count% if /i %count% EQU 12 (set pc=nameofpc) & echo %count% if /i %count% EQU 13 (set pc=nameofpc) & echo %count% if /i %count% EQU 14 echo %count% & (goto end) :: net use \\%pc% :: installation code here.... set /a count +=1 goto loop :end :: script complete :: exit I always surround both sides of IF tests with QUOTES & use double equal signs rather than EQU & I never have this problem. Also, why the parentheses around "goto end"? if /i "%count%"=="10" goto end Quote from: Dias de verano on February 28, 2008, 05:44:34 AM why the parentheses around "goto end"? Force of habit really. I usually have '(goto end) else goto wherever'. I'll have another look at my code later this afternoon.Quote from: blastman on February 28, 2008, 06:41:10 AM I usually have '(goto end) else goto wherever'. That's a good tip. Thanks! well, I've added " " to numbers over 9 (ie. more than one didget) and it seems to have done the trick!! I had done originally and then changed it cos I though it was causing other errors. I must have had it wrong. I've stuck it on a server, scheduled it to run and put it to bed. - (hopefully) job done. Thanks |
|