How to start

Just starting out? Need help? Post your questions and find answers here.
rob206
New User
New User
Posts: 2
Joined: Mon Mar 17, 2014 11:25 pm

How to start

Post by rob206 »

I have downloaded PureBasic 5.21. The formdesigner has no property for the eventfile. How to get things going as I don't know how to start with a simple window, a button and textbox which is filled when I push the button.
I'ts just for my understanding how to setup a basic program with an event file in PureBasic 5,21. I'm familiair in programming in Visual Basic.

Is there a toolbox object like the stringgrid in fnxbasic http://www.fnxbasic.com/index.html spreadsheet like grid or is there an other object in PureBasic with the same functionality.

Thanks for any help.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: How to start

Post by IdeasVacuum »

Welcome to PB rob206.

In the PureBasic Help, there is a "We start programming" chapter. That's the place to start........
http://www.purebasic.com/documentation/ ... rview.html
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: How to start

Post by citystate »

VB does tend to hold your hand a little more - the gadgets in PB all produce event messages that you'll need to check for (something that VB does automatically). Create an event loop like the following

Code: Select all

Repeat
  event=WaitWindowEvent()
  If event = #PB_Event_Gadget
    gadget = EventGadget()
    Select gadget
      Case #Gadget1
        ;do stuff with this Gadget
      Case #Gadget2
        ;do stuff with this Gadget
      Case #Gadget3
        ;do stuff with this Gadget
      Default
        ;maybe do stuff in case you get a gadget event that you don't recognise
    EndSelect
EndIf
Loop Until event = #PB_Event_CloseWindow
Hopefully that gives you a start - you'll need to change the #Gadget* to match your gadget numbers though - have fun
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
atiaust
New User
New User
Posts: 7
Joined: Thu Mar 13, 2014 3:26 am

Re: How to start

Post by atiaust »

Hi Rob206,

I started out last week and had problems trying to get my head around the form designer. I wrote this little step by step help example. Hope it helps.

-----------------------------------------------------------------------------------------------

How To create a windows form & program using the Form Designer in PureBasic 5.21 LTS

1) Create a program file example.pb (Location of procedures)

2) Create a new form file - exampleForm0.pbf (Location of windows events handler)
Note - I usually create these in a new folder For simplicity.

3) Add the Gadgets To the form layout. Rename the gadgets If required, this is in the "variable" parameter in the gadget property window. I Usually start out With a couple of Button Gadgets And a couple of Text Gadgets just To create the basic form layout. The example form has Button_0, Button_1, Text_0 And Text_1.

https://dl.dropboxusercontent.com/u/219 ... eForm0.png Form Layout....

4) In the PureBasic IDE Select Form | Switch Code/Design view To view the generated form code. If you used the Default gadget names it should look like the example below:

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

Global Text_0, Text_1, Button_0, Button_1

Declare Button_0Event(EventType)
Declare Button_1Event(EventType)

Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Example Form ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  Text_0 = TextGadget(#PB_Any, 110, 60, 100, 25, "Text Gadget :")
  Text_1 = TextGadget(#PB_Any, 120, 140, 350, 25, "Click on Buttons below to trigger events", #PB_Text_Center | #PB_Text_Border)
  Button_0 = ButtonGadget(#PB_Any, 130, 250, 100, 25, "Button 0")
  Button_1 = ButtonGadget(#PB_Any, 360, 250, 100, 25, "Button 1")
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_0Event(EventType())          
        Case Button_1
          Button_1Event(EventType())          
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

5) Copy the code below into the example.pb file. This file holds the procedures For the form.

Code: Select all

XIncludeFile "exampleForm0.pbf" ; Include the first window definition
;
Define Event
;
OpenWindow_0()

Procedure Button_0Event(EventType)
  ;Debug "Button_0 Event"
  MessageRequester("Button Event", "Botton 0 Clicked")
  ; Add your code here
EndProcedure

Procedure Button_1Event(EventType)
  ;Debug "Button_1 Event"
  MessageRequester("Button Event", "Botton 1 Clicked")
  ; Add your code here
EndProcedure

Repeat
  Event = WaitWindowEvent()
  
  Select EventWindow()
    Case Window_0
      Window_0_Events(Event) ; This procedure name is always window name followed by '_Events'
      
  EndSelect
Until Event = #PB_Event_CloseWindow ; Quit on any window close
 

6) Return To the design view of the exampleForm0.pbf And check that the Event Procedure property in Button_0 And Button_1 have events assigned. This should be "Button_0Event" And "Button_1Event" respectively.
The selector drop down To the right of the 'Event procedure' should have the events listed provided the procedures are in the example.pb file.

7) Compile And Run the example.pb file. If all works well by clicking on the buttons you should get an acknowledgement message box.

8) Add your code To the Button procedures And start adding new gadgets And procedures.
rob206
New User
New User
Posts: 2
Joined: Mon Mar 17, 2014 11:25 pm

Re: How to start

Post by rob206 »

Hello everybody,

Thanks for all your help I preciate this very much. I'm gonna give it a try :lol:

Well, I build the example and it works! Now I know how. Thanks atiaust.
Post Reply