Task

Given a prompt and a list containing a number of strings of which one is to be selected, create a function that:

 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 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:

   fee fie
   huff and puff
   mirror mirror
   tick tock

Note

This task is fashioned after the action of the Bash select statement.

'The Function
Function Menu(ArrList, Prompt)
    Select Case False   'Non-standard usage hahaha
        Case IsArray(ArrList)
           Menu = ""   'Empty output string for non-arrays
           Exit Function
        Case UBound(ArrList) >= LBound(ArrList)
           Menu = ""   'Empty output string for empty arrays
           Exit Function
    End Select
    'Display menu and prompt
    Do While True
        For i = LBound(ArrList) To UBound(ArrList)
            WScript.StdOut.WriteLine((i + 1) & ". " & ArrList(i))
        Next
        WScript.StdOut.Write(Prompt)
        Choice = WScript.StdIn.ReadLine
        'Check if input is valid
        If IsNumeric(Choice) Then   'Check for numeric-ness
            If CStr(CLng(Choice)) = Choice Then   'Check for integer-ness (no decimal part)
                Index = Choice - 1   'Arrays are 0-based
                'Check if Index is in array
                If LBound(ArrList) <= Index And Index <= UBound(ArrList) Then
                    Exit Do
                End If
            End If
        End If
        WScript.StdOut.WriteLine("Invalid choice.")
    Loop
    Menu = ArrList(Index)
End Function
 
'The Main Thing
Sample = Array("fee fie", "huff and puff", "mirror mirror", "tick tock")
InputText = "Which is from the three pigs: "
WScript.StdOut.WriteLine("Output: " & Menu(Sample, InputText))