My batch informs the user when the value entered is wrong and offers two options: retype the value or exit the program.
@echo off
cls
setlocal enabledelayedexpansion
set /p Value=Enter the value:
for /f skip^=4 %%e in ('echo;prompt $E^|cmd')do set "$E=%%e"
if "!Value!" gtr "10" (
echo %$E%[31mInvalid value! Do you want to re-enter the value? (y=yes/n=exit) %_$E%[0m
IF /i "!r!"=="y" goto RELOADSAMESCREEN
goto :eof
)
The only way I managed to make the message disappear when the retype option is chosen, was to reload the same screen because when the screen is reloaded, the CLS command clears the screen with the message and then loads the screen again, so the message disappears from the screen and the user can re-enter the value without the error message.
How can I clear the message sent by the echo command without having to reload the same screen?
EDITED:
Script changed according to @iTwasnTme answer, it's much better, but the input field keeps duplicating on the screen and the color does not return to white.
Changed script:
@echo off
setlocal enabledelayedexpansion
for /f skip^=4 %%e in ('echo;prompt $E^|cmd')do set "_$E=%%e"
:RELOADSAMESCREEN
color & echo& set /p "_Value=Enter the value: "
if !Value! gtr 10 =;(
set /p "r=!$E![31mInvalid value^!! Do you want to re-enter the value? [y=yes |or| n=exit] "
if /i "!r!"=="y" (set /p "'=!$E


