Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,10 +1,10 @@
|
|||
Given a list containing a number of strings of which one is to be selected and a prompt string, create a function that:
|
||||
Given a prompt and a list containing a number of strings of which one is to be selected, create a function that:
|
||||
|
||||
* Print a textual menu formatted as an index value followed by its corresponding string for each item in the list.
|
||||
* Prompt the user to enter a number.
|
||||
* Return the string corresponding to the index number.
|
||||
* prints a textual menu formatted as an index value followed by its corresponding string for each item in the list;
|
||||
* prompts the user to enter a number;
|
||||
* returns the string corresponding to the selected index number.
|
||||
|
||||
The function should reject input that is not an integer or is an out of range integer index by recreating the whole menu before asking again for a number. The function should return an empty string if called with an empty list.
|
||||
The function should reject input that is not an integer or is out of range by redisplaying the whole menu before asking again for a number. The function should return an empty string if called with an empty list.
|
||||
|
||||
For test purposes use the four phrases: “<tt>fee fie</tt>”, “<tt>huff and puff</tt>”, “<tt>mirror mirror</tt>” and “<tt>tick tock</tt>” in a list.
|
||||
|
||||
|
|
|
|||
28
Task/Menu/Batch-File/menu.bat
Normal file
28
Task/Menu/Batch-File/menu.bat
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
::The Main Thing...
|
||||
set choices="fee fie","huff and puff","mirror mirror","tick tock"
|
||||
set "quest=Which is from the three pigs?"
|
||||
call :select
|
||||
pause>nul
|
||||
exit /b 0
|
||||
::/The Main Thing.
|
||||
|
||||
::The Function...
|
||||
:select
|
||||
set number=0
|
||||
for %%A in (%choices%) do set tmpvar=%%A&set /a number+=1&set opt!number!=!tmpvar:"=!
|
||||
:tryagain
|
||||
cls&echo.
|
||||
for /l %%A in (1,1,%number%) do echo. Option %%A - !opt%%A!
|
||||
echo.
|
||||
set /p input=%quest%
|
||||
for /l %%A in (1,1,%number%) do (
|
||||
if !input! equ %%A echo.&echo.You chose option %%A - !opt%%A!&goto :EOF
|
||||
)
|
||||
echo.
|
||||
echo.Invalid Input. Please try again...
|
||||
pause>nul
|
||||
goto tryagain
|
||||
::/The Function.
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
require'misc'
|
||||
require 'general/misc/prompt' NB. in older versions of J this was: require'misc'
|
||||
showMenu =: i.@# smoutput@,&":&> ' '&,&.>
|
||||
makeMsg =: 'Choose a number 0..' , ': ',~ ":@<:@#
|
||||
errorMsg =: [ smoutput bind 'Please choose a valid number!'
|
||||
|
|
|
|||
|
|
@ -1,17 +1,5 @@
|
|||
PROGRAM:MENU
|
||||
:"FEE FIE"→Str0
|
||||
:"HUFF AND PUFF"→Str1
|
||||
:"MIRROR MIRROR"→Str2
|
||||
:"TICK TOCK"→Str3
|
||||
:Menu("CHOOSE",Str0,A,Str1,B,Str2,C,Str3,D)
|
||||
:Lbl A
|
||||
:Disp Str0
|
||||
:Stop
|
||||
:Lbl B
|
||||
:Disp Str1
|
||||
:Stop
|
||||
:Lbl C
|
||||
:Disp Str2
|
||||
:Stop
|
||||
:Lbl D
|
||||
:Disp Str3
|
||||
1:FEE FIE
|
||||
2:HUFF AND PUFF
|
||||
3:MIRROR MIRROR
|
||||
4:TICK TOCK
|
||||
? [flashing cursor]
|
||||
|
|
|
|||
25
Task/Menu/VBScript/menu.vb
Normal file
25
Task/Menu/VBScript/menu.vb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
Do
|
||||
WScript.StdOut.Write "1. fee fie" & vbCrLf
|
||||
WScript.StdOut.Write "2. huff puff" & vbCrLf
|
||||
WScript.StdOut.Write "3. mirror mirror" & vbCrLf
|
||||
WScript.StdOut.Write "4. tick tock" & vbCrLf
|
||||
WScript.StdOut.Write "Please Enter Your Choice: " & vbCrLf
|
||||
choice = WScript.StdIn.ReadLine
|
||||
Select Case choice
|
||||
Case "1"
|
||||
WScript.StdOut.Write "fee fie" & vbCrLf
|
||||
Exit Do
|
||||
Case "2"
|
||||
WScript.StdOut.Write "huff puff" & vbCrLf
|
||||
Exit Do
|
||||
Case "3"
|
||||
WScript.StdOut.Write "mirror mirror" & vbCrLf
|
||||
Exit Do
|
||||
Case "4"
|
||||
WScript.StdOut.Write "tick tock" & vbCrLf
|
||||
Exit Do
|
||||
Case Else
|
||||
WScript.StdOut.Write choice & " is an invalid choice. Please try again..." &_
|
||||
vbCrLf & vbCrLf
|
||||
End Select
|
||||
Loop
|
||||
Loading…
Add table
Add a link
Reference in a new issue