Page 1 of 1

Sorry, my mind has gone blank

Posted: Fri Jan 26, 2018 11:59 am
by SniffTheGlove
Hi,

I usually write console apps or simple windowed apps where every routine is run from a button press.

Now I am doing this simple window app where once Start button is pressed the routine with continue forever.
I have tried various things but none successful.
I tried searching these forums but just got page after page of other stuff so I am not able to make the search query more precise.

Now how do I detect the stop button being pressed once the start is running.
I have a simple example to illustrate. Press Start, then press stop.

Code: Select all

If OpenWindow(0, 100, 200, 80, 60, "Test...")
  ButtonGadget(2, 10, 1,  75, 25, "Start")
  ButtonGadget(3, 10, 30,  75, 25, "Stop")
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget
      If EventGadget() = 2
        Repeat
          Debug Date() 
          ForEver
        EndIf
        If EventGadget() = 3
        Event = #PB_Event_CloseWindow
      EndIf
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
End
Please help a a blind dummy to see the light :-)
Thanks

Re: Sorry, my mind has gone blank

Posted: Fri Jan 26, 2018 12:05 pm
by HanPBF
Only a fix.

Repeat ... ForEver is not an event loop but an endless loop in itself ("forEver").

Code: Select all

If OpenWindow(0, 100, 200, 80, 60, "Test...")
  ButtonGadget(2, 10, 1,  75, 25, "Start")
  ButtonGadget(3, 10, 30,  75, 25, "Stop")
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget
      If EventGadget() = 2
        Repeat
          Debug Date()
          
	          if WaitWindowEvent()=#PB_Event_Gadget and EventGadget()=3
	          	break
                      Event = #PB_Event_CloseWindow
	          endif
	          
          ForEver
        EndIf
        If EventGadget() = 3
        Event = #PB_Event_CloseWindow
      EndIf
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
End

Re: Sorry, my mind has gone blank

Posted: Fri Jan 26, 2018 12:20 pm
by RASHAD

Code: Select all

If OpenWindow(0, 100, 200, 80, 60, "Test...",#PB_Window_SystemMenu| #PB_Window_ScreenCentered)
  ButtonGadget(2, 10, 1,  75, 25, "Start")
  ButtonGadget(3, 10, 30,  75, 25, "Stop")
  
  AddWindowTimer(0,100,1000)
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1
        
      Case #PB_Event_Timer
        If Flag = 1
          Debug Date()
        EndIf
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 2
            Flag = 1
          
          Case 3
            Flag = 0
            
        EndSelect
    EndSelect
  Until Quit = 1
EndIf
End

Re: Sorry, my mind has gone blank

Posted: Wed Jan 31, 2018 9:39 pm
by SniffTheGlove
Thank you all for your help :-)

Re: Sorry, my mind has gone blank

Posted: Wed Jan 31, 2018 9:45 pm
by infratec
Golden Rule:

Use only on WaitWindowEvent() or WindowEvent() in your hole program :!:

Else you come into trouble. (Sooner or later)