Page 1 of 1

Getting variable output twice after Select Case Menu

Posted: Wed Sep 18, 2019 11:52 am
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!

Re: Getting variable output twice after Select Case Menu

Posted: Wed Sep 18, 2019 12:00 pm
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()

Re: Getting variable output twice after Select Case Menu

Posted: Wed Sep 18, 2019 12:04 pm
by Zimon
Damn! Thanks so much!! :oops:

Re: Getting variable output twice after Select Case Menu

Posted: Wed Sep 18, 2019 3:52 pm
by mk-soft
WindowEvent() -> WaitWindowEvent()

Unless you need a heating plate. 8)