Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to create user menu

Posted on 2007-11-23
8
Medium Priority
?
90 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

722 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