whats difference in menu (help and button)

wheretheidivides

Active Member
Licensed User
Longtime User
What's the difference in the 2 subs for a menu popup? I'm a bit confused. Which one is the one when you press the menu section runs the code? What's difference in 2 subs for menus? I though it was Help_click. So what is Button_click used for again?

Sub Help_Click
Sub Button_Click
 
Last edited:

wheretheidivides

Active Member
Licensed User
Longtime User
It depends on the EventName parameter:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.AddMenuItem("some title", "EventName1")
   Activity.AddMenuItem("some title", "Help")
End Sub

Sub EventName1_Click
   'handles the first item
End Sub
Sub Help_Click
   'handles the second item
End Sub

So I found this way of doing a menu which works, but am sorta of confused.
B4X:
'Menu
   Activity.AddMenuItem("Title Screen","Help") 'top left
   Activity.AddMenuItem("Instructions","Help") 'top center
   Activity.AddMenuItem("Return To Game","Help") 'top right
   
   Activity.AddMenuItem("Zero Stats","Help") 'bottom left
   Activity.AddMenuItem("Practice (On/Off)","Help") 'bottom center
   
   Activity.AddMenuItem("Allow Cont' Bets? (Y/N)","Help") 'more 1
   Activity.AddMenuItem("Allow Double/Triple? (Y/N)","Help") 'more 2
   Activity.AddMenuItem("Allow Splitting Pairs? (Y/N)","Help") 'more 3
   Activity.AddMenuItem("Sound Effects (On/Off)","Help") 'more 4
   Activity.AddMenuItem("Rate and Comment","Help") 'more 5

B4X:
Sub Help_Click
'---------------------------------------------
'Menu
Select Sender
   Case "Title Screen"
      '
            
   Case "Return To Game"
                          '
                  
   Case "Zero Stats"
      Zero 'Subroutine

   Case "Instructions"
      Instruct 'Subroutine
         
   Case "Practice (On/Off)"
      Bug 'Subroutine
      
   Case "Allow Cont' Bets? (Y/N)"
      ContBet ' Subroutine
            
   Case "Allow Double/Triple? (Y/N)"
      DDTD 'SUBROUTINE

   Case "Allow Splitting Pairs? (Y/N)"
      SplitThem'SUBROUTINE
      
   Case "Sound Effects (On/Off)"
      Sound'SUBROUTINE

   Case "Rate and Comment"
      RateComment'SUBROUTINE
      
End Select
'-------------------------------------
End Sub
Sub Button_Click
'---------------------------------------------
'menu
   Dim Send As Button
   Send = Sender
   
   Select Send.Tag
      Case "1"
         '
      Case "2"
         '
      Case "3"
         '
      Case "4"
         '
      Case "5"
         
      Case "6"
         '
      Case "7"
         '
      Case "8"
         '
      Case "9"
         '
      Case "10"
         '
   End Select


So maybe I did this wrong. In this code, the button_click does nothing (Assume there is code where there is a " ' " that makes it do something for the moment). It's actually the help_click that sends it to the subroutines. SO can I delete button_click and it will work OK?

So what you are saying is that instead of doing like this I should have a subroutine labled for each of the helps and delete select sender?

I know the code works, but am trying to figure out why and what is not needed.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I don't think that you understood my answer. The second parameter (EventName) in Activity.AddMenuItem determines which sub will handle the event.

As written in the documentation Sender keyword will return the clicked menu item text.

So what you are saying is that instead of doing like this I should have a subroutine labled for each of the helps and delete select sender?
I didn't say it. I only explained the purpose of EventName. Both options will work fine.
 
Upvote 0
Top