05-12-2025, 08:34 PM
I'm trying to change the active state of my main loop with a simple menu. Everything seems to work, but when I press 'Enter' on the 'Get Out' menu item, nothing happens. QB64PE does pass parameters by reference doesn't it? I'm not really sure why my main loop won't exit.
I hope this isn't something dumb again.
Code: (Select All)
''Create a menu with selectable options
Option _Explicit
$Color:0
''main program area
Dim state&: state& = 1
Do
_Limit (60)
PopUpMenu (state&)
Loop Until state& = 0
Sleep
End
''----------------------Subroutines--------------------------
Sub PopUpMenu (pustate&)
''routine for popup menu - active subsystems should check for their own input
Dim mrtxt$(1 To 4)
mrtxt$(1) = "Hello"
mrtxt$(2) = "Goodbye"
mrtxt$(3) = "Now"
mrtxt$(4) = "Get Out"
Static msel&
''Check for input
If _KeyDown(18432) Then ''up
msel& = msel& - 1
End If
If _KeyDown(20480) Then ''down
msel& = msel& + 1
End If
''wrap menu cursor
If msel& < LBound(mrtxt$) Then msel& = UBound(mrtxt$)
If msel& > UBound(mrtxt$) Then msel& = LBound(mrtxt$)
If _KeyDown(13) Then ''Enter
''Exit the program when enter is pressed on Get Out
If msel& = 4 Then pustate& = 0
End If
''Draw the menu to the screen
DrawMenuBox 3, 4, mrtxt$(), msel&
Sleep .001
End Sub ''PopUpMenu
Sub DrawMenuBox (row&, col&, mtxt$(), hl&)
''Draw a menu Box on the screen
Dim tw&, th&
''Get the number of lines of text to draw and determine the longest
th& = UBound(mtxt$) - LBound(mtxt$) + 1
Dim i
For i = LBound(mtxt$) To UBound(mtxt$)
If Len(mtxt$(i)) > tw& Then tw& = Len(mtxt$(i))
Next
''Generate the text Box
Color Black, White
''top row
Locate row&, col&
Print "�" + String$(tw&, "�") + "�"
''Print txt rows
For i = 1 To th&
Locate row& + i, col&
Print "�" + Space$(tw&) + "�"
Next
''bottom row
Locate row& + th& + 1, col&
Print "�" + String$(tw&, "�") + "�"
''Print text onto box
For i = 1 To th&
If i = hl& Then
Color White, Black
Locate row& + i, col& + 1
Print mtxt$(i) + Space$(tw& - Len(mtxt$(i)))
Color Black, White
Else
Locate row& + i, col& + 1
Print mtxt$(i) + Space$(tw& - Len(mtxt$(i)))
End If
Next
End Sub
I hope this isn't something dumb again.
