Forms Designer Evaluation Question

Just starting out? Need help? Post your questions and find answers here.
JackieBlue
New User
New User
Posts: 6
Joined: Mon Apr 29, 2013 5:53 pm

Forms Designer Evaluation Question

Post by JackieBlue »

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.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4799
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Forms Designer Evaluation Question

Post by Fangbeast »

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?

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
acreis
Enthusiast
Enthusiast
Posts: 250
Joined: Fri Jun 01, 2012 12:20 am

Re: Forms Designer Evaluation Question

Post by acreis »

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.
JackieBlue
New User
New User
Posts: 6
Joined: Mon Apr 29, 2013 5:53 pm

Re: Forms Designer Evaluation Question

Post by JackieBlue »

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.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Forms Designer Evaluation Question

Post by PB »

> 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. :shock:

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.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Forms Designer Evaluation Question

Post by Tenaja »

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.
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).
acreis
Enthusiast
Enthusiast
Posts: 250
Joined: Fri Jun 01, 2012 12:20 am

Re: Forms Designer Evaluation Question

Post by acreis »

Hi

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

Here is the PB equivalent

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
User
Posts: 54
Joined: Mon Nov 26, 2012 4:57 pm

Re: Forms Designer Evaluation Question

Post by Lothar Schirm »

A good description how to use the Form Designer can be found here:
http://forums.purebasic.com/english/vie ... 3ce6078488
:lol:
JackieBlue
New User
New User
Posts: 6
Joined: Mon Apr 29, 2013 5:53 pm

Re: Forms Designer Evaluation Question

Post by JackieBlue »

Thanks everyone. I'll plug away at it some tomorrow.
Post Reply