Menu: Difference between revisions
→{{header|VBScript}}: corrected
Alpha bravo (talk | contribs) (Added AutoHotkey) |
Simple9371 (talk | contribs) (→{{header|VBScript}}: corrected) |
||
Line 3,094:
=={{header|VBScript}}==
<lang vb>'The Function▼
Function Menu(ArrList)
▲<lang vb>
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
choice = WScript.StdIn.ReadLine▼
'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("Which is from the three pigs: ")
'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 Select
End If
Loop▼
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")
WScript.StdOut.WriteLine("Output: " & Menu(Sample))</lang>
{{Out}}
▲F:\>cscript /nologo menu.vbs
1. fee fie
2. huff and puff
3. mirror mirror
4. tick tock
Which is from the three pigs: cdsfklfm
Invalid choice.
1. fee fie
2. huff and puff
3. mirror mirror
4. tick tock
Which is from the three pigs: -2
Invalid choice.
1. fee fie
2. huff and puff
3. mirror mirror▼
4. tick tock
Which is from the three pigs: 3.14159
Invalid choice.
1. fee fie
2. huff and puff
3. mirror mirror
4. tick tock
Which is from the three pigs: 45
Invalid choice.
1. fee fie
2. huff and puff
3. mirror mirror
4. tick tock
Which is from the three pigs: 2
Output: huff and puff</pre>
▲mirror mirror
=={{header|XPL0}}==
|