How to resolve the algorithm Menu step by step in the AutoHotkey programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Menu step by step in the AutoHotkey programming language
Table of Contents
Problem Statement
Given a prompt and a list containing a number of strings of which one is to be selected, create a function that:
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 following four phrases in a list: This task is fashioned after the action of the Bash select statement.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Menu step by step in the AutoHotkey programming language
Source code in the autohotkey programming language
Menu(list:=""){
if !list ; if called with an empty list
return ; return an empty string
for i, v in x := StrSplit(list, "`n", "`r")
string .= (string?"`n":"") i "- " v
, len := StrLen(v) > len ? StrLen(v) : len
while !x[Choice]
InputBox , Choice, Please Select From Menu, % string ,, % 200<len*7 ? 200 ? len*7 , % 120 + x.count()*20
return x[Choice]
}
list =
(
fee fie
huff and puff
mirror mirror
tick tock
)
MsgBox % Menu(list) ; call menu with list
MsgBox % Menu() ; call menu with empty list
return
You may also check:How to resolve the algorithm Order by pair comparisons step by step in the Factor programming language
You may also check:How to resolve the algorithm Hash join step by step in the Ruby programming language
You may also check:How to resolve the algorithm Stem-and-leaf plot step by step in the 11l programming language
You may also check:How to resolve the algorithm Guess the number step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Amicable pairs step by step in the K programming language