Menu: Difference between revisions

(Added AutoHotkey)
Line 3,094:
 
=={{header|VBScript}}==
<lang vb>'The Function
{{incorrect|VBScript|The function should return an empty string if called with an empty list. Please also check if this could really used as a [https://en.wikipedia.org/wiki/Subroutine function aka subroutine.]}}
Function Menu(ArrList)
<lang vb>
Select Case False 'Non-standard usage hahaha
Do
Case IsArray(ArrList)
WScript.StdOut.Write "1. fee fie" & vbCrLf
Menu = "" 'Empty output string for non-arrays
WScript.StdOut.Write "2. huff puff" & vbCrLf
Exit Function
WScript.StdOut.Write "3. mirror mirror" & vbCrLf
Case UBound(ArrList) >= LBound(ArrList)
WScript.StdOut.Write "4. tick tock" & vbCrLf
Menu = "" 'Empty output string for empty arrays
WScript.StdOut.Write "Please Enter Your Choice: " & vbCrLf
Exit Function
choice = WScript.StdIn.ReadLine
End Select
Select Case choice
'Display menu and prompt
Case "1"
Do While True
WScript.StdOut.Write "fee fie" & vbCrLf
For i = LBound(ArrList) To UBound(ArrList)
Exit Do
WScript.StdOut.WriteLine((i + 1) & ". " & ArrList(i))
Case "2"
Next
WScript.StdOut.Write "huff puff" & vbCrLf
WScript.StdOut.Write("Which is from the three pigs: ")
Exit Do
choice Choice = WScript.StdIn.ReadLine
Case "3"
'Check if input is valid
WScript.StdOut.Write "mirror mirror" & vbCrLf
If IsNumeric(Choice) Then 'Check for numeric-ness
Exit Do
If CStr(CLng(Choice)) = Choice Then 'Check for integer-ness (no decimal part)
Case "4"
Index = Choice - 1 'Arrays are 0-based
WScript.StdOut.Write "tick tock" & vbCrLf
'Check if Index is in array
Exit Do
If LBound(ArrList) <= Index And Index <= UBound(ArrList) Then
Case Else
Exit Do
WScript.StdOut.Write choice & " is an invalid choice. Please try again..." &_
End If
vbCrLf & vbCrLf
End If
End Select
End If
Loop
WScript.StdOut.WriteLine("Invalid choice.")
</lang>
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<pre>C:\>cscript /nologo menu.vbs
<pre>
 
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
Please Enter Your Choice:
Invalid choice.
9
9 is an invalid choice. Please try again...
 
1. fee fie
2. huff and puff
3. mirror mirror
4. tick tock
Which is from the three pigs: -2
Please Enter Your Choice:
Invalid choice.
f
1. fee fie
f is an invalid choice. Please try again...
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
Please Enter Your Choice:
Output: huff and puff</pre>
3
mirror mirror
</pre>
 
=={{header|XPL0}}==
535

edits