Page 1 of 1

Working with variable

Posted: 02 Jul 2015 12:21
by alexandredneto
Hello guys.

In the code below, in the first loop to enter the value 1234 in the ID field.
In the second loop, key to enter without entering any value in the ID field.

It is considered the previous value. How to correct it? Delete the variable?

Thanks.

Code: Select all

@echo off
SET create_user="criar_usuario.cmd"
SET delete_user="delete_user.cmd"
SET create_shortcut="create_shortcut.cmd"
SET delete_shortcut="delete_shortcut.cmd"
SET change_pw="change_pw.cmd"

:top

cls
echo -------------------------------------------------------------------------------
echo Enter an option:
echo (1) Create the User
echo
echo (2) Delete the User
echo
echo (3) Create the Shortcut
echo
echo (4) Delete the Shortcut
echo
echo (5) Change password
echo
echo (6) Exit
echo -------------------------------------------------------------------------------

CHOICE /C 123456 /N /M "Enter a number 1-6: "
SET OPNUM=%ERRORLEVEL%
IF %OPNUM% EQU 1 (
   setlocal enabledelayedexpansion
   set /p "ID=Enter ID: "
   set /p "name=Enter Name: "
   call %create_user% !ID! !name!
   endlocal
   )
IF %OPNUM% EQU 2 (
   setlocal enabledelayedexpansion
   set /p "ID=Enter ID: "
   call %delete_user% !ID!
   endlocal
   )
IF %OPNUM% EQU 3 (
   setlocal enabledelayedexpansion
   set /p "ID=Enter ID: "
   call %create_shortcut% !ID!
   endlocal
   )
IF %OPNUM% EQU 4 (
   setlocal enabledelayedexpansion
   set /p "ID=Enter ID: "
   call %delete_shortcut% !ID!
   endlocal
   )
IF %OPNUM% EQU 5 (
   setlocal enabledelayedexpansion
   set /p "ID=Enter ID: "
   call %change_pw% !ID!
   endlocal
   )
IF %OPNUM% EQU 6 goto close
goto top

:close
echo -------------------------------------------------------------------------------
echo Finished
echo -------------------------------------------------------------------------------
exit /b 0

Re: Working with variable

Posted: 02 Jul 2015 12:29
by Squashman
set "id="

Re: Working with variable

Posted: 02 Jul 2015 12:30
by aGerman
Delete the variable?

Un-define it.

Code: Select all

set "ID="
set /p "ID=Enter ID: "

Regards
aGerman