[DONE] #PB_event_gadget - Constant not found?

Just starting out? Need help? Post your questions and find answers here.
PresFox
User
User
Posts: 33
Joined: Sat Jan 19, 2008 9:30 am

[DONE] #PB_event_gadget - Constant not found?

Post 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!
Last edited by PresFox on Sat Apr 03, 2010 6:20 pm, edited 1 time in total.
User of PB 4.41 - x86
On Windows 7
Intel Core I5 2.26GHZ
8 GB RAM
ATI Mobility Radeon HD 5650
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: #PB_event_gadget - Constant not found?

Post by Perkin »

The correct constant is #PB_Event_Gadget (notice the second underscore)
%101010 = $2A = 42
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: #PB_event_gadget - Constant not found?

Post by Kaeru Gaman »

use Autocomplete to avoid such little glitches..
oh... and have a nice day.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: #PB_event_gadget - Constant not found?

Post 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)
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
PresFox
User
User
Posts: 33
Joined: Sat Jan 19, 2008 9:30 am

Re: #PB_event_gadget - Constant not found?

Post by PresFox »

thanks for the help guys, works now
User of PB 4.41 - x86
On Windows 7
Intel Core I5 2.26GHZ
8 GB RAM
ATI Mobility Radeon HD 5650
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

Re: #PB_event_gadget - Constant not found?

Post by UserOfPure »

Don't forget that #PB_EventCloseWindow is now #PB_Event_CloseWindow too.
Post Reply