Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Ranguna173
- Posts: 104
- Joined: 28 Jul 2011 17:32
#1
Post
by Ranguna173 » 07 Apr 2013 13:34
Hi everyone.
I wrote a script that isn't working as I want it to and I can't find out why.
It is supposed to write the number you have written (>5) times 60 but instead it just doesn't calculate that. (line 16)
Here's the code:
Code: Select all
::@echo on &setlocal enableDelayedExpansion
set a=0
set b=false
set /p a=[Type a number geq 5]:
echo %a%|findstr /r "[^0-9]" > nul
if errorlevel 1 (
if %a% geq 5 (
set b=true
) else (
echo "was less then 5">output
)
) else (
echo "wasn't a number">output
)
if %b%==true (
set /a a=%a%*60
echo "%a%">output
pause
)
set b=false
(echo is set as a commentary to enable it just remove the "::")
If you need any other info please ask.
Thanks

-
Endoro
- Posts: 244
- Joined: 27 Mar 2013 01:29
- Location: Bozen
#2
Post
by Endoro » 07 Apr 2013 13:50
You need delayed expansion.
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "a=0"
set "b=false"
set /p "a=[Type a number geq 5]: "
echo %a%|findstr /r "[^0-9]" > nul
if errorlevel 1 (
if %a% geq 5 (
set "b=true"
) else (
echo "was less then 5">con
)
) else (
echo "wasn't a number">con
)
if "%b%"=="true" (
set /a a=%a%*60
echo "!a!">con
pause
)
set "b=false"
Replace "con" with your output file name.
-
Ranguna173
- Posts: 104
- Joined: 28 Jul 2011 17:32
#3
Post
by Ranguna173 » 07 Apr 2013 14:03
Endoro wrote:You need delayed expansion.
Replace "con" with your output file name.
I replaced "output" with "con" and it didn't save any output file.
Re-replace "con" with "output" but kept the changes to the "a" variable (%a% --> !a! (line 17)) while Delayed expansions was enabled and it worked.
I totaly forgot to change %% to !!, gotta note that somewhere so I wont forget again
Thanks for the help Endoro
