Working with variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alexandredneto
Posts: 39
Joined: 28 Feb 2013 13:40

Working with variable

#1 Post by alexandredneto » 02 Jul 2015 12:21

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

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Working with variable

#2 Post by Squashman » 02 Jul 2015 12:29

set "id="

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Working with variable

#3 Post by aGerman » 02 Jul 2015 12:30

Delete the variable?

Un-define it.

Code: Select all

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

Regards
aGerman

Post Reply