dimanche 29 décembre 2019

Looping with if statement in batch

I write a batch file to store the error message using the if loops. But there is no result coming out from the index 0. I am feeling so weird about it and I have been scratching my head the whole day. Here is the code:

:loops
  IF DEFINED result[%num1%] (
REM call echo number %num1% %%result[!num1!]%%
REm call echo Time    : %%result[!num1!]:~9,8%%
REM call echo Value  : %num1%
REM call SET timeInLog[!num1!]=%%result[!num1!]:~9,8%%


call SET nHour=%%result[!num1!]:~9,2%%
call SET nMins=%%result[!num1!]:~12,2%%
call SET nSec=%%result[!num1!]:~15,2%%
call SET timeinlog=%nHour%%nMins%%nSec%
call echo %num1% and time : !timeinlog!
SET /A num1+=1
goto :loops
)
pause

The result is:

0 and time :
1 and time : 090747
2 and time : 112418
3 and time : 121641
4 and time : 181427
Press any key to continue . . .

Aucun commentaire:

Enregistrer un commentaire