Execute numbers choices more than 9

  • Thread starter Thread starter happytoday
  • Start date Start date
H

happytoday

That is my be silly an old question but I do not know how to use the
shift batch command in expanding options of choices more than 9
options.

:Main_Menu
@cls
@echo off
@echo Returned Envelops Script
@echo --------------------------
@echo.
@echo.
@echo 1-ID Entry to a single file
@echo.
@echo 2-Check/Delete ID duplication in a single
@echo.
@echo 3-Check ID Entry in ALL Sorted Files
@echo.
@echo 4-Sort/create And Print Sorted Files
@echo.
@echo 5-Count Envelops Entries in a sorted date
@echo.
@echo 6-Search Double Entries by Customer Number
@echo.
@echo 7-Search Entry by Customer Number
@echo.
@echo 8-Search Entry by Account
@echo.
@echo 9-Exit
@echo.
%binaries%\choice /C:987654321 Choose an
option ?

@if errorlevel 9 call return_entry
@if errorlevel 8 call return_double
@if errorlevel 7 call return_douentry
@if errorlevel 6 call return_sortprnt
@if errorlevel 5 call return_count
@if errorlevel 4 call return_chkdou
@if errorlevel 3 call return_chkmis
@if errorlevel 2 call return_chkmis_acc 2>error
@if errorlevel 1 call Exit
 
happytoday said:
That is my be silly an old question but I do not know how to use the
shift batch command in expanding options of choices more than 9
options.

:Main_Menu
@cls
@echo off
@echo Returned Envelops Script
@echo --------------------------
@echo.
@echo.
@echo 1-ID Entry to a single file
@echo.
@echo 2-Check/Delete ID duplication in a single
@echo.
@echo 3-Check ID Entry in ALL Sorted Files
@echo.
@echo 4-Sort/create And Print Sorted Files
@echo.
@echo 5-Count Envelops Entries in a sorted date
@echo.
@echo 6-Search Double Entries by Customer Number
@echo.
@echo 7-Search Entry by Customer Number
@echo.
@echo 8-Search Entry by Account
@echo.
@echo 9-Exit
@echo.
%binaries%\choice /C:987654321 Choose an
option ?

@if errorlevel 9 call return_entry
@if errorlevel 8 call return_double
@if errorlevel 7 call return_douentry
@if errorlevel 6 call return_sortprnt
@if errorlevel 5 call return_count
@if errorlevel 4 call return_chkdou
@if errorlevel 3 call return_chkmis
@if errorlevel 2 call return_chkmis_acc 2>error
@if errorlevel 1 call Exit

If there are 3 arguments to a command CMD %1 %2 %3
%1 = FIRST
%2 = SECOND
%3 = THIRD
and you do a shift
I think
%1 = SECOND
%2 = THIRD
and there is not %3

See http://www.robvanderwoude.com/parameters.html
 
That is my be silly an old question but I do not know how to use the
shift batch command in expanding options of choices more than 9
options.

:Main_Menu
@cls
@echo off
@echo Returned Envelops Script
@echo --------------------------
@echo.
@echo.
@echo 1-ID Entry to a single file
@echo.
@echo 2-Check/Delete ID duplication in a single
@echo.
@echo 3-Check ID Entry in ALL Sorted Files
@echo.
@echo 4-Sort/create And Print Sorted Files
@echo.
@echo 5-Count Envelops Entries in a sorted date
@echo.
@echo 6-Search Double Entries by Customer Number
@echo.
@echo 7-Search Entry by Customer Number
@echo.
@echo 8-Search Entry by Account
@echo.
@echo 9-Exit
@echo.
%binaries%\choice /C:987654321 Choose an
option ?

@if errorlevel 9 call return_entry
@if errorlevel 8 call return_double
@if errorlevel 7 call return_douentry
@if errorlevel 6 call return_sortprnt
@if errorlevel 5 call return_count
@if errorlevel 4 call return_chkdou
@if errorlevel 3 call return_chkmis
@if errorlevel 2 call return_chkmis_acc 2>error
@if errorlevel 1 call Exit

%binaries%\choice /C:FEDCBA987654321 Choose an option ?

@if errorlevel 11 call optionB
@if errorlevel 10 call optionA
@if errorlevel 9 call return_entry

Tom Lavedas
===========
 
happytoday said:
That is my be silly an old question but I do not know how to use the
shift batch command in expanding options of choices more than 9
options.

:Main_Menu
@cls
@echo off
@echo Returned Envelopes Script
@echo --------------------------
@echo.
@echo.
@echo 1-ID Entry to a single file
@echo.
@echo 2-Check/Delete ID duplication in a single
@echo.
@echo 3-Check ID Entry in ALL Sorted Files
@echo.
@echo 4-Sort/create And Print Sorted Files
@echo.
@echo 5-Count Envelops Entries in a sorted date
@echo.
@echo 6-Search Double Entries by Customer Number
@echo.
@echo 7-Search Entry by Customer Number
@echo.
@echo 8-Search Entry by Account
@echo.
@echo 9-Exit
@echo.
%binaries%\choice /C:987654321 Choose an
option ?

@if errorlevel 9 call return_entry
@if errorlevel 8 call return_double
@if errorlevel 7 call return_douentry
@if errorlevel 6 call return_sortprnt
@if errorlevel 5 call return_count
@if errorlevel 4 call return_chkdou
@if errorlevel 3 call return_chkmis
@if errorlevel 2 call return_chkmis_acc 2>error
@if errorlevel 1 call Exit

As others have pointed out, the Shift command does not come
into this. It is only used when processing command line parameters.

You could tighten your current code like so:

%binaries%\choice /C:987654321 Choose an option ?
call Sub%ErrorLevel%

To make it work, you must manually rename your subroutines like so:
return_entry.bat = sub9.bat
return_double.bat = sub8.bat
etc.
 
%binaries%\choice /C:FEDCBA987654321      Choose an option ?

@if errorlevel 11 call optionB
@if errorlevel 10 call optionA
@if errorlevel 9 call return_entry

Tom Lavedas
===========- Hide quoted text -

- Show quoted text -

with option 16 I should use 2 numbers which is 19 accoding to Hex
system . Please How can I use shift to exceed numbers as far as I want
as to for example 40 options ?
Is there a way to exceed options other than shift command .
 
happytoday said:
That is my be silly an old question but I do not know how to use the
shift batch command in expanding options of choices more than 9
options.

Since you also posted to microsoft.public.windowsxp.general besides
alt.msdos.batch (which is about MS-DOS+Win../95/98/Me) I take it
your OS is XP.

40} How to get the number of and parse the arguments given to a script?
http://www.netikka.net/tsneti/info/tscmd040.htm
http://www.netikka.net/tsneti/info/tscmd014.htm

All the best, Timo
 
happytoday said:
That is my be silly an old question but I do not know how to use the
shift batch command in expanding options of choices more than 9
options.

I can't see any benefit in prefixing all lines with @ - just set it once
with the top "@echo off"
:Main_Menu
@cls
@echo off
@echo Returned Envelops Script
@echo --------------------------
In the UK we spell it "Envelopes"
@echo.
@echo.
@echo 1-ID Entry to a single file
@echo.
@echo 2-Check/Delete ID duplication in a single
@echo.
@echo 3-Check ID Entry in ALL Sorted Files
@echo.
@echo 4-Sort/create And Print Sorted Files
@echo.
@echo 5-Count Envelops Entries in a sorted date
@echo.
@echo 6-Search Double Entries by Customer Number
@echo.
@echo 7-Search Entry by Customer Number
@echo.
@echo 8-Search Entry by Account
@echo.
@echo 9-Exit
@echo.
%binaries%\choice /C:987654321 Choose an
option ?

"choice" allows for any of the "any" keys to be entered, not just
numbers. "set /P" is the replacement in XP.
@if errorlevel 9 call return_entry
if any of your subroutines set an errorlevel you may find unwanted extra
calls - in this case I think it sensible to use "goto"s. Each of these
sections then end with "goto Main_Menu"
@if errorlevel 8 call return_double
@if errorlevel 7 call return_douentry
@if errorlevel 6 call return_sortprnt
@if errorlevel 5 call return_count
@if errorlevel 4 call return_chkdou
@if errorlevel 3 call return_chkmis
@if errorlevel 2 call return_chkmis_acc 2>error
@if errorlevel 1 call Exit


As others have hinted "shift" doesn't help with this kind of problem.
My approach is to subdivide into submenus all with <=9 options, with 0
as the goback up/exit option
 
happytoday said:
That is my be silly an old question but I do not know how to use the
shift batch command in expanding options of choices more than 9
options.
[snip]
%binaries%\choice /C:FEDCBA987654321 Choose an option ?

@if errorlevel 11 call optionB
@if errorlevel 10 call optionA
@if errorlevel 9 call return_entry

Tom Lavedas
===========- Hide quoted text -

- Show quoted text -

with option 16 I should use 2 numbers which is 19 accoding to Hex
system . Please How can I use shift to exceed numbers as far as I want
as to for example 40 options ?
Is there a way to exceed options other than shift command .

A few matters to get out of the way before this whole discussion goes off
the rails:

1. SHIFT has nothing to do with the CHOICE command. The variables "%1" to
"%9" refer to the FIRST to NINTH parameters supplied to the batch file. If
there are more than 9, you may use SHIFT to drop the first parameter, and
thereafter %1 refer to the second...%9 refers to the tenth. Use SHIFT as
many times as are required to shffle the parameters along to the
"accessible" range.

2. The line

@echo off

makes further use of a leading "@" redundant. It turns command-echo OFF
unless it is specifically turned back ON again by a command

ECHO ON

3. Hex has nothing to do with the discussion. The syntax of IF ERRORLEVEL
requires DECIMAL.


So - to add more options the easy way:
a) Reverse the CHOICES string. ERRORLEVEL is set up as the position number
within this string of the key used. Lot easier if "1" is first, "2" second
and so on.

Hence:

%binaries%\choice /C:123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ Choose an
option ?

This will give you up to 36 choices.

if errorlevel 36 optionZ
if errorlevel 35 optionY
....
if errorlevel 2 option2
if errorlevel 1 option1


If you need more than 36 choices, either add symbols to the list (# or $ ,
etc) or use lower-case as well, where you'd have to add the "/S" switch to
CHOICE

%binaries%\choice /S /C:123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ#$abc Choose
an option ?

if errorlevel 41 lowerc
if errorlevel 40 lowerb
if errorlevel 39 lowera
if errorlevel 38 dollar
if errorlevel 37 hash
if errorlevel 36 optionZ
if errorlevel 35 optionY

And a further caution:

Your

if errorlevel nn CALL something

is not incorrect BUT when "something" is executed, it will leave ERRORLEVEL
set to some value. It is likely that this would be zero, but if it is not,
you may get unexpected results.

For instance:

if errorlevel 32 call OPTION32
....

where OPTION32.BAT contains

--------OPTION32.BAT starts -------------
@echo off
.....
find "x" result.txt>nul
if not errorlevel 1 echo We found x in result.txt
--------OPTION32.BAT ends -------------

Under these circumstances, when OPTION32.BAT returns, if "x" was NOT found
in result.txt then ERRORLEVEL will be 1, so the CHOICE line for errorlevel 1
will be executed.


There are two common solutions to this:

1) program YOURMENU.BAT as

....
if errorlevel 41 lowerc
if errorlevel 40 lowerb
....

then have each of your submenu files (lowerc.bat, lowerb.bat etc.) execute

YOURMENU

as the final command.

2) program within YOURMENU.BAT

@echo off
....
:again
choice.....
if errorlevel 41 goto lowerc
if errorlevel 40 goto lowerb
....

:lowerb
....
goto again

:lowerc
....
goto again

although this method would tend to be very clumsy indeed as many people
would be tempted to put all of the code for all of the options within this
one file.

Of course, you could also try using the MENU command - but it's been so long
since I went anywhere near that, I'm not going to attempt a MENU solution...
 
with option 16 I should use 2 numbers which is 19 accoding to Hex
system . Please How can I use shift to exceed numbers as far as I want
as to for example 40 options ?
Is there a way to exceed options other than shift command .


@echo off
choice /C:1234567890 /n "enter digit one: "

if errorlevel 1 set tens=1
if errorlevel 2 set tens=2
if errorlevel 3 set tens=3
if errorlevel 4 set tens=4
if errorlevel 5 set tens=5
if errorlevel 6 set tens=6
if errorlevel 7 set tens=7
if errorlevel 8 set tens=8
if errorlevel 9 set tens=9
if errorlevel 10 set tens=0

choice /C:1234567890 /n "enter digit two: "

if errorlevel 1 set units=1
if errorlevel 2 set units=2
if errorlevel 3 set units=3
if errorlevel 4 set units=4
if errorlevel 5 set units=5
if errorlevel 6 set units=6
if errorlevel 7 set units=7
if errorlevel 8 set units=8
if errorlevel 9 set units=9
if errorlevel 10 set units=0

if "%tens%%units%"=="01" call 01.bat
if "%tens%%units%"=="02" call 02.bat
if "%tens%%units%"=="03" call 03.bat
if "%tens%%units%"=="04" call 04.bat
if "%tens%%units%"=="05" call 05.bat
pause
 
foxidrive said:
@echo off
choice /C:1234567890 /n "enter digit one: "

if errorlevel 1 set tens=1
if errorlevel 2 set tens=2
if errorlevel 3 set tens=3
if errorlevel 4 set tens=4
if errorlevel 5 set tens=5
if errorlevel 6 set tens=6
if errorlevel 7 set tens=7
if errorlevel 8 set tens=8
if errorlevel 9 set tens=9
if errorlevel 10 set tens=0

choice /C:1234567890 /n "enter digit two: "

Why not set a time out for the second choice? This way you can,
like with a TV remote control, enter one digit numbers or within
2 second two digit numbers.
 
Back
Top