Getting variable output twice after Select Case Menu

Just starting out? Need help? Post your questions and find answers here.
Zimon
User
User
Posts: 12
Joined: Wed Jul 10, 2019 8:18 pm

Getting variable output twice after Select Case Menu

Post by Zimon »

Hello,

I have the following simple menu to call a procedure:

Code: Select all

Enumeration

  #MAIN_WINDOW
  #MAIN_BUTTON_EXIT
  #MAIN_BUTTON_0
  
  #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered

EndEnumeration

Procedure Button_0()
  x = 1
  Debug x
EndProcedure

Procedure MainWindow()
  
  OpenWindow(#MAIN_WINDOW, 0, 0, 300, 200, "Main Window", #FLAGS)
  ButtonGadget(#MAIN_BUTTON_EXIT,230,180,70,20,"Quit")
  ButtonGadget(#MAIN_BUTTON_0,60,80,175,40,"Run Procedure with Button_0")  
  
    Repeat ; main program loop
      MainWindowLoop = WindowEvent()
      
      Select EventGadget() ; this is apparently needed to make the button do stuff!
          
        Case #MAIN_BUTTON_0
          Button_0()
          
        Case #MAIN_BUTTON_EXIT
          Quit = #True  
          
      EndSelect
      
    Until MainWindowLoop = #PB_Event_CloseWindow Or Quit = #True
  
EndProcedure

MainWindow()
The output of the debug command is

Code: Select all

1
1
The problem is I simply don't understand why I get a doubled output for variable x. So far, I've found out that is apparently has something to do with the case menu selection

Can someone enlighten me? I am running v5.70. Thanks!
User avatar
robertfern
User
User
Posts: 38
Joined: Fri Feb 02, 2018 10:33 pm
Location: New Jersey

Re: Getting variable output twice after Select Case Menu

Post by robertfern »

You forgot another select statement to handle the "MainWindowLoop"

Code: Select all

Enumeration

  #MAIN_WINDOW
  #MAIN_BUTTON_EXIT
  #MAIN_BUTTON_0
  
  #FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered

EndEnumeration

Procedure Button_0()
  x = 1
  Debug x
EndProcedure

Procedure MainWindow()
  
  OpenWindow(#MAIN_WINDOW, 0, 0, 300, 200, "Main Window", #FLAGS)
  ButtonGadget(#MAIN_BUTTON_EXIT,230,180,70,20,"Quit")
  ButtonGadget(#MAIN_BUTTON_0,60,80,175,40,"Run Procedure with Button_0")  
  
  Repeat ; main program loop
    MainWindowLoop = WindowEvent()
    Select MainWindowLoop ; this is needed to test what type of event happened
      Case #PB_Event_Gadget ;  this is needed to detect if it is a gadget event
        Select EventGadget() ; this is apparently needed to make the button do stuff!
            
          Case #MAIN_BUTTON_0
            Button_0()
            
          Case #MAIN_BUTTON_EXIT
            Quit = #True  
            
        EndSelect
    EndSelect
  Until MainWindowLoop = #PB_Event_CloseWindow Or Quit = #True
  
EndProcedure

MainWindow()
Mac OSX Ventura & Windows 10, PB 6.12
Zimon
User
User
Posts: 12
Joined: Wed Jul 10, 2019 8:18 pm

Re: Getting variable output twice after Select Case Menu

Post by Zimon »

Damn! Thanks so much!! :oops:
User avatar
mk-soft
Always Here
Always Here
Posts: 6286
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Getting variable output twice after Select Case Menu

Post by mk-soft »

WindowEvent() -> WaitWindowEvent()

Unless you need a heating plate. 8)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply