Forms Designer Evaluation Question
-
JackieBlue
- New User

- Posts: 6
- Joined: Mon Apr 29, 2013 5:53 pm
Forms Designer Evaluation Question
Merry Christmas to those who celebrate. I'm an experienced Visual Basic programmer from VB3 to VB 2008 (and some 2012). I am trying to evaluate PB for a project that I would like to be multi-platform rather than just Windows, plus I would like to get away from Microsoft's bloated files for relatively simple applications. Part of my evaluation is to download the PB IDE and run a couple of tests that basically amount to create a basic window form, connect to a db, and read out of the db. However, I'm getting somewhat confused on what I thought would be the most basic part - creating of the form and handling the events on it. The manual is not clear and the videos I found on it did not seem to match what I was seeing in the demo IDE/compiler. So, are there any up to date demos out there, in English, that shows creating of a basic form with events? How about coding for events? I guess it also could be a limitation of the demo version of PB but I would think it would say that when downloaded. Thanks and happy holidays.
- Fangbeast
- PureBasic Protozoa

- Posts: 4799
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Forms Designer Evaluation Question
The IDE is limited in demo mode to around 800 lines (I think) and no Windows API useable, the events themselves are not limited.
Although I am not aware of any tutorials as most coders are too busy, does my simple minded example below help at all?
Although I am not aware of any tutorials as most coders are too busy, does my simple minded example below help at all?
Code: Select all
;- Window Constants
Enumeration 1
#Window_HelloWindow
EndEnumeration
#WindowIndex = #PB_Compiler_EnumerationValue
;- Gadget Constants
Enumeration 1
; Window_HelloWindow
#Gadget_HelloWindow_HelloButton
EndEnumeration
#GadgetIndex = #PB_Compiler_EnumerationValue
; Neatly encapsulated windows procedure that returns a window handle that you can test for
Procedure.l Window_HelloWindow()
If OpenWindow(#Window_HelloWindow, 80, 80, 400, 45, "Hello there!", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible)
ButtonGadget(#Gadget_HelloWindow_HelloButton, 10, 10, 380, 25, "Press me to print Hello!")
SetGadgetFont(#Gadget_HelloWindow_HelloButton, LoadFont(#Gadget_HelloWindow_HelloButton, "Comic Sans MS", 10, 0))
HideWindow(#Window_HelloWindow, 0)
ProcedureReturn WindowID(#Window_HelloWindow)
EndIf
EndProcedure
;- Main event handler loop
If Window_HelloWindow()
QuitProgram.i = 0
Repeat
EventID = WaitWindowEvent()
MenuID = EventMenu()
GadgetID = EventGadget()
WindowID = EventWindow()
Select EventID
Case #PB_Event_CloseWindow
Select WindowID
Case #Window_HelloWindow ; Check if the user pressed the windows close 'x' in the title bar
QuitProgram.i = 1
EndSelect
Case #PB_Event_Gadget
Select GadgetID
Case #Gadget_HelloWindow_HelloButton ; Button gadget that gets checked for being pressed
SetWindowTitle(#Window_HelloWindow, "Thank you for pressing the hello button!")
EndSelect
EndSelect
Until QuitProgram.i
CloseWindow(#Window_HelloWindow)
EndIf
End
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Re: Forms Designer Evaluation Question
Hi
I'm a sort of amateur programmer, starting with Fortran (early 80's) Clipper (summer 87/DOS) throug VB 3 - 6 and vb.net 2008. Now I'm using PB Windows.
Maybe because I have started with a procedural language (Clipper), I have no dificulties with PB.
The only issue I had is about Office integration and Access database. Srod's librarie comate (free) solved this. Another issue is the absence of a Datagridview gadget. Again Srod can help (paid) , and there is some free alternatives around the forum.
I hope my opinion can help you.
I'm a sort of amateur programmer, starting with Fortran (early 80's) Clipper (summer 87/DOS) throug VB 3 - 6 and vb.net 2008. Now I'm using PB Windows.
Maybe because I have started with a procedural language (Clipper), I have no dificulties with PB.
The only issue I had is about Office integration and Access database. Srod's librarie comate (free) solved this. Another issue is the absence of a Datagridview gadget. Again Srod can help (paid) , and there is some free alternatives around the forum.
I hope my opinion can help you.
-
JackieBlue
- New User

- Posts: 6
- Joined: Mon Apr 29, 2013 5:53 pm
Re: Forms Designer Evaluation Question
thanks for the responses. I just don't see how the events get created. VB creates the event for you - such as on_click, mouse_over, etc. Looks like this requires you to type your own events. I didn't see examples for this or how to differentiate between different types of events.
Re: Forms Designer Evaluation Question
> I just don't see how the events get created
The form designer is very confusing, yes. I don't use it for that reason.
In fact, I just tried it to write a step-by-step example but I gave up.
I assigned a procedure to a ButtonGadget in the gadget's property box
but clicking the button at runtime does NOT call the procedure.
Anyway, see here for how you can type events manually:
http://www.purebasic.com/documentation/ ... et.pb.html
At least until the form designer gets working more intuitively.
The form designer is very confusing, yes. I don't use it for that reason.
In fact, I just tried it to write a step-by-step example but I gave up.
I assigned a procedure to a ButtonGadget in the gadget's property box
but clicking the button at runtime does NOT call the procedure.
Anyway, see here for how you can type events manually:
http://www.purebasic.com/documentation/ ... et.pb.html
At least until the form designer gets working more intuitively.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: Forms Designer Evaluation Question
Look at the example that PB linked to. The gadgets are manually assigned a gadget number--in practice, it is typically better to use an enumeration so you can name the ID's to make it much more readable. Anyway, the last Repeat-Until loop in the sample handles the events. You should have a loop like this to handle all events. There are several types of events (i.e. EventGadget, EventWindow, EventMenu, etc.), so you test for each type that you have used (in the Select-Case statements), and then process each element (the Case statements).JackieBlue wrote:thanks for the responses. I just don't see how the events get created. VB creates the event for you - such as on_click, mouse_over, etc. Looks like this requires you to type your own events. I didn't see examples for this or how to differentiate between different types of events.
Re: Forms Designer Evaluation Question
Hi
I hope the folowing minimal example helps.
Here is a vb.net snippet.
Create an application with Form1 and Button1 on it
Here is the PB equivalent
I hope the folowing minimal example helps.
Here is a vb.net snippet.
Create an application with Form1 and Button1 on it
Code: Select all
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Debug.Print("Button click event on Button1")
End Sub
End Class
Code: Select all
; Comments start with a semicolon
Procedure Button1_Click()
Select EventType()
Case #PB_EventType_LeftClick
Debug "Mouse Left Click event on gadget (Button) number" + EventGadget()
EndSelect
EndProcedure
Procedure Main()
OpenWindow(1, 100, 100, 200, 50, "Form1", #PB_Window_SystemMenu) ;Create Form1
ButtonGadget(1, 10, 10, 180, 30, "Button1") ;Create Button1
BindGadgetEvent(1, @Button1_Click()) ; atach event handler procedure to "Button1" gadget
;we always need an event loop ....
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndProcedure
Main() ;calling main procedure ....
-
Lothar Schirm
- User

- Posts: 54
- Joined: Mon Nov 26, 2012 4:57 pm
Re: Forms Designer Evaluation Question
A good description how to use the Form Designer can be found here:
http://forums.purebasic.com/english/vie ... 3ce6078488

http://forums.purebasic.com/english/vie ... 3ce6078488
-
JackieBlue
- New User

- Posts: 6
- Joined: Mon Apr 29, 2013 5:53 pm
Re: Forms Designer Evaluation Question
Thanks everyone. I'll plug away at it some tomorrow.

