Solved

Need to create user menu

Posted on 2007-11-23
8
83 Views
Last Modified: 2014-11-21
How do I create a user menu where the bat file asks for info such as name, etc., and then let the person type in the answer which will be saved in the set feature of the .bat file?  

0
Comment
Question by:ttranscripts2
8 Comments
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20340845
You can prompt the user with the set /p command:

set /p ans=Continue Y/N?

if "%ans%"=="" goto :EOF
0
 
LVL 28

Accepted Solution

by:
Naveen Kumar earned 250 total points
ID: 20348617
Just some sample code to show a menu and get an answer :

echo off
set myvar=
echo pick which one you want?:
echo A ( apples )
set avar=Apples
echo B ( Beauties )
set bvar=Beauties
echo C ( computers )
set cvar=Computers
set /p myvar="Enter your choice (A/B/C):"
echo %myvar%
echo Your Selection is:
if "%myvar%" == "A" ( echo %avar% )
if "%myvar%" == "B" ( echo %bvar% )
if "%myvar%" == "C" ( echo %cvar% )

Thanks
0
 
LVL 3

Expert Comment

by:top_gizmo
ID: 20391598
For what you want, you may need to go to a simple vbscript.  It is way more dynamic and you can save the variable "name" etc into a file to retrieve later.  If you want an actual GUI, I would look at AutoIt from www.hiddensoft.com its Free.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 11

Expert Comment

by:paultomasi
ID: 34226867
The easy part is getting stuff in.

There are TWO difficult parts:

   1. (and I can't emphasise this enough) anticipating what the user will enter at the keyboard

   2. validating the data entered by the user

In short, things never go wrong until they are in the hands of the user!

Let me add just one more thought to this.

Anticipating what the user will enter is NOT the same as expecting what the user will enter.

For example, suppose you want the user to enter a name such as JOHN SMITH.

The user doesn't know how the data is handled by your batch file so he thinks nothing of entering something like JOHN F SMITH or J SMITH or even J F SMITH. How about J. F. SMITH or even J.F.SMITH.

Suppose he accidentally hits the '#' key when pressing ENTER. You end up with something like JOHN SMITH#.
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 34322641
ttranscripts2
nav_kum_v

I prefer to use  arrays for lists and menus. Run the following code for an example.



@echo off
setlocal enabledelayedexpansion
set fruit[1]=Apple
set fruit[2]=Banana
set fruit[3]=Cranberry
set fruit[4]=Date

echo.
for /l %%i in (1,1,4) do echo %%i. !fruit[%%i]!

echo.
set /p choice=Select fruit [1-4]:

echo.
echo You chose !fruit[%choice%]!


0
 
LVL 10

Expert Comment

by:ReneGe
ID: 35307163
How about this?

Cheers,
Rene

 
@ECHO OFF

SETLOCAL enabledelayedexpansion

SET Database=%~n0.txt
SET Data.ROW1=First Name
SET Data.ROW2=Last Name
SET Data.ROW3=Age
SET Data.ROW4=Magic Number

:Home
CLS
CHOICE /M "DO YOU WISH TO CREATE A NEW USER?"
IF %errorlevel% == 2 GOTO DisplayData


:NewUser
CLS
IF "%TheUser%" NEQ "" (ECHO LAST USER ENTERS WAS: [%TheUser%] & ECHO.)
ECHO PLEASE ENTER USER INFORMATION AS FOLLOWES
ECHO FIRST NAME,LAST NAME,AGE,MAGIC NUMBER
SET /P TheUser=
REM IF NAME DOES NOT EXIST, ADD IT TO THE DATABASE 
	IF NOT EXIST "%Database%" (
		ECHO %TheUser%>>%Database%
	) ELSE (
	FINDSTR -i /C:"%TheUser%" %Database% >NUL || ECHO %TheUser%>>%Database%
	)
ECHO.
CHOICE /M "DO YOU WISH TO CREATE A NEW USER?"
IF %errorlevel% == 1 GOTO NewUser



:DisplayData
REM READING USERS IN THE DATABASE TO ARRAY
	FOR /F "TOKENS=1-4 DELIMS=," %%A IN (%Database%) DO (
		SET /a UserNb+=1
		SET Data.ROW1.!UserNb!=%%A
		SET Data.ROW2.!UserNb!=%%B
		SET Data.ROW3.!UserNb!=%%C
		SET Data.ROW4.!UserNb!=%%D
	)

REM CHOOSING WHAT USER IS TO BE DISPLAYED
	ECHO PLEASE CHOOSE WHAT USER YOU WISH TO DISPLAY INFORMATION
	ECHO -------------------------------------------------------
	FOR /L %%A IN (1,1,%UserNb%) DO (
		ECHO %%A- !Data.ROW1.%%A! !Data.ROW2.%%A!
		SET Choices=!Choices!%%A
	)
	ECHO.
	CHOICE /C %Choices%
	ECHO.

REM DISPLAYING THE CHOOSEN DATA
	ECHO.
	ECHO.
	ECHO USER DATA
	ECHO -------------------------------------
	ECHO %Data.ROW1%: !Data.ROW1.%errorlevel%!
	ECHO %Data.ROW2%: !Data.ROW2.%errorlevel%!
	ECHO %Data.ROW3%: !Data.ROW3.%errorlevel%!
	ECHO %Data.ROW4%: !Data.ROW4.%errorlevel%!
	ECHO.

PAUSE
EXIT

Open in new window

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question