Menu: Difference between revisions
Content added Content deleted
Alpha bravo (talk | contribs) (Added AutoHotkey) |
Simple9371 (talk | contribs) (→{{header|VBScript}}: corrected) |
||
Line 3,094: | Line 3,094: | ||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
⚫ | |||
{{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) |
|||
⚫ | |||
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 |
|||
⚫ | |||
⚫ | |||
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 |
|||
⚫ | |||
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 If |
|||
⚫ | |||
WScript.StdOut.WriteLine("Invalid choice.") |
|||
</lang> |
|||
⚫ | |||
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}} |
{{Out}} |
||
⚫ | |||
<pre> |
|||
⚫ | |||
1. fee fie |
1. fee fie |
||
2. huff puff |
2. huff and puff |
||
3. mirror mirror |
3. mirror mirror |
||
4. tick tock |
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 |
1. fee fie |
||
2. huff puff |
2. huff and puff |
||
3. mirror mirror |
3. mirror mirror |
||
4. tick tock |
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 |
|||
⚫ | |||
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 |
1. fee fie |
||
2. huff puff |
2. huff and puff |
||
3. mirror mirror |
3. mirror mirror |
||
4. tick tock |
4. tick tock |
||
Which is from the three pigs: 2 |
|||
Please Enter Your Choice: |
|||
Output: huff and puff</pre> |
|||
3 |
|||
⚫ | |||
</pre> |
|||
=={{header|XPL0}}== |
=={{header|XPL0}}== |