It could be handy some day

Moderator: DosItHelp
Adrianvdh wrote:I need the technique to be like mine, the if errorlevel statement must be in the function.
And I need the use switches.
alan_b wrote:Adrianvdh wrote:I need the technique to be like mine, the if errorlevel statement must be in the function.
And I need the use switches.
Sorry if old age has made me cynical,
but this sounds to me like a request for assistance with a school's homework exercise,
where the requirement is not to achieve a particular result,
but to demonstrate the correct syntax for using errorlevel and switches as taught in the last lesson.
aGerman wrote:Try to write a simplified example (whole batch code) that shows the problem.
Regards
aGerman
Code: Select all
choice /C 12r /N /M "Make your selection: "
if errorlevel 3 cls & goto restart
if errorlevel 2 ( set mainmenuvar=Text1
goto mainmenuloginput )
Code: Select all
set mylevel=%errorlevel%
choice /C 12r /N /M "Make your selection: "
if %mylevel%==3 (cls & goto restart)
if %mylevel%==2 ( set mainmenuvar=Text1
goto mainmenuloginput )
Code: Select all
set choice=%errorlevel%
choice /C 123456itr /N /M "Make your selection: "
echo %choice%
pause
Code: Select all
choice /C 12 /N /M "Make your selection: "
echo %123%
echo %errorlevel%
pause
goto mainmenu
if "%errorlevel%"=="2" ( set mainmenuvar=Msg
goto mainmenuloginput )
if "%errorlevel%"=="1" ( set mainmenuvar=Msg
goto mainmenuloginput )
:mainmenuloginput
if "%logmode%"=="Enabled" call :checkfileUAC "/l" if "%logtype%"=="Detailed" echo [%time%] [%mainmenuvar%]>>"%logdir%"
if "%errorlevel%"=="2" goto Test2
if "%errorlevel%"=="1" goto Test1
penpen wrote:Code: Select all
choice /C 12 /N /M "Make your selection: "
set "errno=%errorlevel%"
:: ...
::replace: if errorlevel 2 goto Test2
if %errno% GEQ 2 goto Test2
::replace: if errorlevel 1 goto Test1
if %errno% GEQ 1 goto Test1
Adrianvdh wrote:I tried this:Code: Select all
set choice=%errorlevel%
choice /C 123456itr /N /M "Make your selection: "
echo %choice%
pause
and the errorlevel returned as 0
Code: Select all
choice /C 123456itr /N /M "Make your selection: "
set choice=%errorlevel%
echo %choice%
pause
If you store the errorlevel immidiately as i've suggested and use it later (errno, see post above) then its content would be that of the errorlevel after using choice.Adrianvdh wrote:Then I tried:Code: Select all
choice /C 12 /N /M "Make your selection: "
echo %123%
echo %errorlevel%
pause
goto mainmenu
if "%errorlevel%"=="2" ( set mainmenuvar=Msg
goto mainmenuloginput )
if "%errorlevel%"=="1" ( set mainmenuvar=Msg
goto mainmenuloginput )
:mainmenuloginput
if "%logmode%"=="Enabled" call :checkfileUAC "/l" if "%logtype%"=="Detailed" echo [%time%] [%mainmenuvar%]>>"%logdir%"
if "%errorlevel%"=="2" goto Test2
if "%errorlevel%"=="1" goto Test1
After the goto mainmenuloginput is executed the errorlevel must mess up, and it does it return a 1 after the function is called. Any idea?
It computes the sum of all positive natural numbers up to %~2 (n):Adrianvdh wrote:You extra computing code, does not make sense to me - sorry I am a retard? Could you explain what it does exactly and in details?
It could be handy some day.
Code: Select all
if "%logmode%"=="Enabled" if "%logtype%"=="Detailed" call :checkfileUAC "/l" && echo [%time%] [%mainmenuvar%]>>"%logdir%"
Adrianvdh wrote:@alan_b:
Do I need to set var=%errorlevel% befor I call the UAC Function? because your code does not work