Menu question

wheretheidivides

Active Member
Licensed User
Longtime User
I have a menu that crashes every one in a while. I click on it and it works for 1 sec and then sometimes crashes. This is the menu. My question is what does "Sub Button_Click" do and how is it related to Sub Help_Click? I am not sure what to put there or even if it is nessasary. and what does Send.Tag do? and how is all this related to 'sender'? I'm a little fuzzy on this,

Thanks


B4X:
Sub Activity_Create(FirstTime As Boolean)
'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


Sub Help_Click
'---------------------------------------------
'Menu
Select Sender
   Case "Title Screen"
      'turn on panel
         Panel1.Visible=True 'on

      'turn off other panels
         Panel3.Visible=False
         Panel4.Visible=False

         Panel71.Visible=False
         Panel72.Visible=False
         Panel73.Visible=False
         Panel74.Visible=False
         Panel75.Visible=False
         Panel75B.Visible=False
         Panel76.Visible=False
         Panel77.Visible=False
         Panel78.Visible=False
         Panel79.Visible=False
         Panel80.Visible=False
            
   Case "Return To Game"
      Panel1.Visible=False
      Panel3.Visible=False
      
      If DebugOn = True Then
         Panel4.Visible=True
      Else If DebugOn=False Then
         Panel4.Visible=False
      End If
      
      Panel71.Visible=False
      Panel72.Visible=False
      Panel73.Visible=False
      Panel74.Visible=False
      Panel75.Visible=False
      Panel75B.Visible=False
      Panel76.Visible=False
      Panel77.Visible=False
      Panel78.Visible=False
      Panel79.Visible=False
      Panel80.Visible=False
                  
   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
'-------------------------------------
End Sub
 

wheretheidivides

Active Member
Licensed User
Longtime User
Another example is this one. I don't understand how the Sub Button_Click comes into play.


B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("MenuPanels")
   Activity.AddMenuItem("Help1","Help")
   Activity.AddMenuItem("Help2","Help")
   Activity.AddMenuItem("Help3","Help")
   Panel1.Top = 0
   Panel1.Left = 0
   Panel2.Top = 0
   Panel2.Left = 0
   Panel3.Top = 0
   Panel3.Left = 0
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Help_Click
   Select Sender
   Case "Help1"
      Panel1.Visible=True
   Case "Help2"
      Panel2.Visible=True
   Case "Help3"
      Panel3.Visible=True
   End Select
End Sub

Sub Button_Click
   Dim Send As Button
   
   Send = Sender
   
   Select Send.Tag
   Case "1"
      Panel1.Visible=False
   Case "2"
      Panel2.Visible=False
   Case "3"
      Panel3.Visible=False
   End Select
End Sub
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
@wheretheidivides

the command activity.AddMenuItem is used:

Activity.AddMenuItem("This is the text of the menu item ie. What you see","This is the sub which will be called when the menu item is selected")

In your case,

B4X:
Activity.AddMenuItem("Help1","Help")

The text is "Help1" as visible text and the sub called is Help_Click (As you generate a click event) Clear?

None of your menu items call the Button sub and therefore it is not used.

The .Tag is a useful place to store place to store info, string or number. If for example you had a series of buttons with numbers like a calculator, you could store the value of the button in the .Tag property. Menu items do not have a .Tag property, only views. Hope this helps a little.

Also please look here Link

ps. You seem to be adding rather a lot of menu items. Maybe a panel with options would be better. Just a thought.

Regards
Mark
 
Upvote 0
Top