Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
50
Task/Menu/Gambas/menu.gambas
Normal file
50
Task/Menu/Gambas/menu.gambas
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
Public Sub Main()
|
||||
|
||||
Dim asMenu As String[] = ["fee fie", "huff And puff", "mirror mirror", "tick tock"]
|
||||
Dim sValuePrompt As String = "Please select one of the above numbers> "
|
||||
Dim sChoice As String
|
||||
Dim sFeedbackFormat As String = "You have chosen '&1'\r\n"
|
||||
|
||||
sChoice = Menu(asMenu, sValuePrompt)
|
||||
If sChoice = "" Then
|
||||
Print "menu returned an empty string"
|
||||
Else
|
||||
Print Subst(sFeedbackFormat, sChoice)
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
Private Function Menu(asChoices As String[], sPrompt As String) As String
|
||||
|
||||
Dim sReturnValue As String = ""
|
||||
Dim sMenuLineFormat As String = "&1) &2"
|
||||
Dim sAnswer As String
|
||||
Dim iAnswer As Integer
|
||||
Dim iIndex As Integer = 0
|
||||
Dim sMenuItem As String
|
||||
|
||||
If Not IsNull(asChoices) Then
|
||||
If asChoices.Count > 0 Then
|
||||
Do
|
||||
For iIndex = 0 To asChoices.Max
|
||||
sMenuItem = asChoices[iIndex]
|
||||
Print Subst(sMenuLineFormat, iIndex, sMenuItem)
|
||||
Next
|
||||
|
||||
Print sPrompt
|
||||
Input sAnswer
|
||||
|
||||
If IsNumber(sAnswer) Then
|
||||
iAnswer = sAnswer
|
||||
If (0 <= iAnswer) And (iAnswer <= asChoices.Max) Then
|
||||
sReturnValue = asChoices[iAnswer]
|
||||
Break
|
||||
Endif
|
||||
Endif
|
||||
Loop
|
||||
Endif
|
||||
Endif
|
||||
|
||||
Return sReturnValue
|
||||
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue