Hi Vern,
Here's the corrected code for you. When associating an event procedure with a button using the form designer, add it in the "Event procedure" field without any parameters or parentheses:
The generated code for that will say Declare button_clicked(EventType). You can't add any additional parameters to this or it won't match the actual function.
xRainbow.pbf
Code: Select all
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
Global Window_0 ; ProgramName: xRainbow.pb
Global Image_0, Button_0, ListView_0, ListView_1, ListView_2, ListView_3, Text_0, Text_1, Text_2, Text_3
Declare button_clicked(eventType)
Procedure OpenWindow_0(x = 0, y = 0, width = 800, height = 490)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Hex Colors in Rainbow Sequence", #PB_Window_SystemMenu)
Image_0 = ImageGadget(#PB_Any, 20, 20, 150, 50, 0)
Button_0 = ButtonGadget(#PB_Any, 20, 100, 150, 24, "START")
ListView_0 = ListViewGadget(#PB_Any, 260, 50, 100, 420)
ListView_1 = ListViewGadget(#PB_Any, 390, 50, 100, 420)
ListView_2 = ListViewGadget(#PB_Any, 520, 50, 100, 420)
ListView_3 = ListViewGadget(#PB_Any, 650, 50, 120, 420)
Text_0 = TextGadget(#PB_Any, 270, 10, 80, 30, " Pixel POS")
Text_1 = TextGadget(#PB_Any, 400, 10, 80, 30, " Pixel HEX")
Text_2 = TextGadget(#PB_Any, 530, 10, 90, 30, " Html HEX")
Text_3 = TextGadget(#PB_Any, 660, 10, 100, 30, "Html Name")
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case Button_0
button_clicked(EventType())
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
xRainbow.pb
Code: Select all
; ProgramName: xRainbow.pb
IncludeFile "xRainbow.pbf"
UsePNGImageDecoder()
OpenWindow_0()
Procedure button_clicked(eventType)
MessageRequester("Starting:", "And away we go !")
If LoadImage(0, "RainbowBar.png")
; ImageGadget(10, 120, 150, 50, 83, ImageID(0)) ; imagegadget standard
; Malformed line
;Result = ImageGadget(#Gadget, x, y, Width, Height, ImageID [, #PB_Image_Raised)
Result = ImageGadget(10, x, y, Width, Height, ImageID(0), #PB_Image_Raised)
EndIf
EndProcedure
Repeat
e = WaitWindowEvent()
;When using the form designer, you need to send any received events from your event loop to the form's event procedure.
;if you had multiple windows, you'd check which window caused the event and send that event to the proper event procedure
;for that window. Something like this:
; If EventWindow() = Window_0
; Window_0_Events(e)
; ElseIf EventWindow() = Window_2
; Window_2_events(e)
; EndIf
;You only have one window so we don't need to check that.
Window_0_Events(e) ;Send event to form's event procedure
;if you had other things you wanted to do with that event, you'd add them here like so:
; If e = #PB_Event_Gadget
; Debug "gadget event"
; EndIf
Until e = #PB_Event_CloseWindow
End
Also, if you'd like to at some point combine the files into one for easier sharing with other users like Vera said, all you usually have to do is copy the form's code to the top of your main file and comment out the xinclude for the form. Just don't save the file in this state if you'd still like to be able to use the form designer to make modifications later. Here's what it would look like as one file:
Code: Select all
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
Global Window_0 ; ProgramName: xRainbow.pb
Global Image_0, Button_0, ListView_0, ListView_1, ListView_2, ListView_3, Text_0, Text_1, Text_2, Text_3
Declare button_clicked(eventType)
Procedure OpenWindow_0(x = 0, y = 0, width = 800, height = 490)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Hex Colors in Rainbow Sequence", #PB_Window_SystemMenu)
Image_0 = ImageGadget(#PB_Any, 20, 20, 150, 50, 0)
Button_0 = ButtonGadget(#PB_Any, 20, 100, 150, 24, "START")
ListView_0 = ListViewGadget(#PB_Any, 260, 50, 100, 420)
ListView_1 = ListViewGadget(#PB_Any, 390, 50, 100, 420)
ListView_2 = ListViewGadget(#PB_Any, 520, 50, 100, 420)
ListView_3 = ListViewGadget(#PB_Any, 650, 50, 120, 420)
Text_0 = TextGadget(#PB_Any, 270, 10, 80, 30, " Pixel POS")
Text_1 = TextGadget(#PB_Any, 400, 10, 80, 30, " Pixel HEX")
Text_2 = TextGadget(#PB_Any, 530, 10, 90, 30, " Html HEX")
Text_3 = TextGadget(#PB_Any, 660, 10, 100, 30, "Html Name")
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case Button_0
button_clicked(EventType())
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
; ProgramName: xRainbow.pb
;IncludeFile "xRainbow.pbf"
UsePNGImageDecoder()
OpenWindow_0()
Procedure button_clicked(eventType)
MessageRequester("Starting:", "And away we go !")
If LoadImage(0, "RainbowBar.png")
; ImageGadget(10, 120, 150, 50, 83, ImageID(0)) ; imagegadget standard
;Result = ImageGadget(#Gadget, x, y, Width, Height, ImageID [, #PB_Image_Raised)
Result = ImageGadget(10, x, y, Width, Height, ImageID(0), #PB_Image_Raised)
EndIf
EndProcedure
Repeat
e = WaitWindowEvent()
;When using the form designer, you need to send any received events from your event loop to the form's event procedure.
;if you had multiple windows, you'd check which window caused the event and send that event to the proper event procedure
;for that window. Something like this:
; If EventWindow() = Window_0
; Window_0_Events(e)
; ElseIf EventWindow() = Window_2
; Window_2_events(e)
; EndIf
;You only have one window so we don't need to check that.
Window_0_Events(e) ;Send event to form's event procedure
;if you had other things you wanted to do with that event, you'd add them here like so:
; If e = #PB_Event_Gadget
; Debug "gadget event"
; EndIf
Until e = #PB_Event_CloseWindow
End