Page 1 of 1

[DONE] #PB_event_gadget - Constant not found?

Posted: Fri Apr 02, 2010 11:39 am
by PresFox
Hello,

Im just trying a bit with PB, but my very first try is already failing :(

I have a simple menu, designed with the visual designer, and i want to handle input from it

my code is this:

Code: Select all

Repeat
    EventID=WaitWindowEvent();we get the windowevent
    
    Select EventID;we check which window event are we receiving
    
      Case #PB_EventGadget
        Select EventGadgetID()
          Case #button_0 ; the user click the button
            MessageRequester("button clicked","hello world",0)
            SetGadgetText(#Text_1,"clicked!!");Then we put a text into the string gadget
        EndSelect
    
    EndSelect
    
  Until EventID=#PB_EventCloseWindow;loop until the user decide to close the window
EndIf
End
But im getting the error that #PB_EventGadget is not found

my pb version is 4.41

Thanks in advance!

Re: #PB_event_gadget - Constant not found?

Posted: Fri Apr 02, 2010 11:47 am
by Perkin
The correct constant is #PB_Event_Gadget (notice the second underscore)

Re: #PB_event_gadget - Constant not found?

Posted: Fri Apr 02, 2010 12:09 pm
by Kaeru Gaman
use Autocomplete to avoid such little glitches..

Re: #PB_event_gadget - Constant not found?

Posted: Fri Apr 02, 2010 6:33 pm
by Rook Zimbabwe
Of course you could always let the VD create the program loop for you. I learned to code in PB that way (coming from QB4.5) and I have been pretty happy with it.

EXAMPLE:

Code: Select all


Enumeration
  #Window_0
EndEnumeration

Enumeration
  #Button_2
  #Text_HAPPEN
  #Button_1
EndEnumeration

Structure VisualDesignerGadgets
  Gadget.l
  EventFunction.l
EndStructure

Global NewList EventProcedures.VisualDesignerGadgets()


Procedure Button_2_Event(Window, Event, Gadget, Type)
  Debug "#Button_2"
  SetGadgetText(#Text_HAPPEN, "* BUTTON 2 PRESSED!!! *")
EndProcedure

;Procedure Text_HAPPEN_Event(Window, Event, Gadget, Type)
;  Debug "#Text_HAPPEN"
; *** You don't need an event for this since nothing happens if it is clicked on
;EndProcedure

Procedure Button_1_Event(Window, Event, Gadget, Type)
  Debug "#Button_1"
  SetGadgetText(#Text_HAPPEN, "BUTTON ONE PRESSED!!!")
EndProcedure
;-
Procedure RegisterGadgetEvent(Gadget, *Function)
  
  If IsGadget(Gadget)
    AddElement(EventProcedures())
    EventProcedures()\Gadget        = Gadget
    EventProcedures()\EventFunction = *Function
  EndIf
  
EndProcedure

Procedure CallEventFunction(Window, Event, Gadget, Type)
  
  ForEach EventProcedures()
    If EventProcedures()\Gadget = Gadget
      CallFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type)
      LastElement(EventProcedures())
    EndIf
  Next
  
EndProcedure
;-
Procedure Open_Window_0()
  
  If OpenWindow(#Window_0, 5, 5, 400, 187, "GADGET WINDOW",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
   ; If CreateGadgetList(WindowID(#Window_0))
      ButtonGadget(#Button_1, 15, 55, 370, 50, "GADGET  1")
      RegisterGadgetEvent(#Button_1, @Button_1_Event())
      TextGadget(#Text_HAPPEN, 15, 10, 370, 30, "", #PB_Text_Center | #PB_Text_Border)
     ; RegisterGadgetEvent(#Text_HAPPEN, @Text_HAPPEN_Event()) ; *** not needed
      ButtonGadget(#Button_2, 15, 110, 370, 55, "GADGET 2")
      RegisterGadgetEvent(#Button_2, @Button_2_Event())
      
 ;   EndIf ; ***** The second set are REM out because 4.4+ does not need them
  EndIf
EndProcedure

Open_Window_0()

Repeat
  
  Event  = WaitWindowEvent()
  Gadget = EventGadget()
  Type   = EventType()
  Window = EventWindow()
  
  Select Event
    Case #PB_Event_Gadget
      CallEventFunction(Window, Event, Gadget, Type)
      
  EndSelect
  
Until Event = #PB_Event_CloseWindow

End
All the code was created by the VD and I REM out what isn't really needed. I modify this to create a MAP now instead of a list but the essence is the same.
8)

Re: #PB_event_gadget - Constant not found?

Posted: Sat Apr 03, 2010 4:03 pm
by PresFox
thanks for the help guys, works now

Re: #PB_event_gadget - Constant not found?

Posted: Sun Apr 04, 2010 3:42 am
by UserOfPure
Don't forget that #PB_EventCloseWindow is now #PB_Event_CloseWindow too.