Page 1 of 2

Just started,

Posted: Sat May 03, 2008 5:42 pm
by oToom
Hey,
i have just started with this language.
I haven't made anything as of yet. But i will shortly i am sure.
I have been coding in other languages now for a while.
Mainly doing web development.

So i thought this could be an easy chance back into the Software side.

Just a couple of questions before i get started,
-Does this language code with sockets and internet?
For example, making some sort of web browser?
Also in sockets making some sort of irc bot?

I will be using this for whatever i can so,
Thanks.

Posted: Sat May 03, 2008 9:53 pm
by mrjiles
PureBasic has a full network library available, so virtually anything network can be made.

Posted: Sat May 03, 2008 10:51 pm
by oToom
Sounds cool.

The console applications seem quite easy.

i am having problems with / when using the Visual Editor.
I make a button, just so that when i click it i get a pop up, yet i don't know how to do it.

Like in VB you get like a On_Click do you get these on here?

Posted: Sat May 03, 2008 11:06 pm
by Rook Zimbabwe
HideWindow() will do that for you... really simple.

Code: Select all


Enumeration
  #Window_POPUP ; set up gadgets
  #Window_MAIN
EndEnumeration

Enumeration
  #Button_CLOSEPOPUP
  #Text_0
  #Button_OPENPOPUP
EndEnumeration
; the followingis done by the Visual Designer
Structure VisualDesignerGadgets
  Gadget.l
  EventFunction.l
EndStructure

Global NewList EventProcedures.VisualDesignerGadgets()
; gadget list
Procedure Button_CLOSEPOPUP_Event(Window, Event, Gadget, Type)
  Debug "#Button_CLOSEPOPUP"
  HideWindow(#Window_POPUP,1) ; HideWindow(NAME,STATUS) = 1 HIDDEN
EndProcedure

Procedure Button_OPENPOPUP_Event(Window, Event, Gadget, Type)
  Debug "#Button_OPENPOPUP"
  HideWindow(#Window_POPUP,0) ; HideWindow(NAME,STATUS) = 0 SHOW
EndProcedure
; the following allows the program to understand what to do when someone presses a gadget
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_MAIN()
  
  If OpenWindow(#Window_MAIN, 129, 26, 299, 132, "Window MAIN",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
    If CreateGadgetList(WindowID(#Window_MAIN))
      ButtonGadget(#Button_OPENPOPUP, 10, 70, 275, 45, "CLICK TO OPEN POPUP")
      RegisterGadgetEvent(#Button_OPENPOPUP, @Button_OPENPOPUP_Event())
      TextGadget(#Text_0, 10, 25, 275, 20, "CLICK THE BUTTON TO OPEN A POPUP WINDOW!!!", #PB_Text_Center)
            
    EndIf
  EndIf
EndProcedure

Procedure Open_Window_POPUP()
  If OpenWindow(#Window_POPUP, 247, 78, 298, 79, "Window POPUP",  #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_Invisible ) 
  ; The #PB_Window_Invisible makes it hidden until called upon
    If CreateGadgetList(WindowID(#Window_POPUP))
      ButtonGadget(#Button_CLOSEPOPUP, 10, 10, 275, 50, "CLICK TO CLOSE POPUP WINDOW")
      RegisterGadgetEvent(#Button_CLOSEPOPUP, @Button_CLOSEPOPUP_Event())
    EndIf
  EndIf
EndProcedure

Open_Window_POPUP()

Open_Window_MAIN()

Repeat
  
  Event  = WaitWindowEvent(3) ; allow other tasks to process
  Gadget = EventGadget()
  Type   = EventType()
  Window = EventWindow()
  
  Select Event
    Case #PB_Event_Gadget
      CallEventFunction(Window, Event, Gadget, Type)
      
  EndSelect
  
Until Event = #PB_Event_CloseWindow

End
Pretty simple really!

You should Read the Manual and a lot of code. 8)

Posted: Sat May 03, 2008 11:11 pm
by oToom
This stuff seems quite hard at first sight.

Is it actually easier than it looks?

Posted: Sun May 04, 2008 12:20 am
by Seymour Clufley
Is it actually easier than it looks?
Yip.

PureBasic is a very rewarding language. It enables you to do many, many, many different things. It's very flexible and it cuts out a lot of unnecessary syntax nonsense that plagues other languages.

But it enables you to do so many things because it doesn't do everything for you. You are in full control. Therefore, yes, there's quite a lot to learn.

BUT, because of the simplicity of the language, learning it gets easy very quickly, if you stay with it.

Posted: Sun May 04, 2008 11:34 am
by Trond
Simpler:

Code: Select all

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))

Button = ButtonGadget(#PB_Any, 10, 10, 97, 23, "Click me!")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case Button
          MessageRequester("Title", "Ouch, don't poke me like that!!!")
      EndSelect
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
Or with a real window:

Code: Select all

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))

Button = ButtonGadget(#PB_Any, 10, 10, 197, 23, "Click me many times")

OpenWindow(1, 0, 0, 200, 200, "Small window", #PB_Window_Invisible)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case Button
          HideWindow(1, Hidden)
          Hidden = (-Hidden)+1
      EndSelect
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver

Posted: Sun May 04, 2008 12:33 pm
by Kale
If you want a good place to start with Purebasic, my book is as good as any. :wink:

Posted: Sun May 04, 2008 3:22 pm
by oToom
Kale wrote:If you want a good place to start with Purebasic, my book is as good as any. :wink:
I will be buying it soon.
Thank you.

EDIT: Would you mind me asking, on average how many people have bought it?

EDIT2: Damn i can't get it, they don't accept Visa Electron damnit.

Posted: Sun May 04, 2008 9:49 pm
by Kale
oToom wrote:Would you mind me asking, on average how many people have bought it?
I don't mind saying, roughly 400+ people have bought it so far and not a bad word has ever been said! Which surprises me for my first book! :lol: I only expected to sell 200+ so i'm happy. :D

Posted: Sun May 04, 2008 10:27 pm
by oToom
Okay, when my dad is back i will order a copy.

By the way. Does this book go through console AND gui?

Edit: You wouldn't be kind enough to put both, the ebook and hardcopy of the book on amazon would you?

Thank you.

Posted: Mon May 05, 2008 10:57 pm
by ricardo
oToom wrote:Sounds cool.

The console applications seem quite easy.

i am having problems with / when using the Visual Editor.
I make a button, just so that when i click it i get a pop up, yet i don't know how to do it.

Like in VB you get like a On_Click do you get these on here?

Code: Select all

If OpenWindow(0,100,150,450,200,"Test",#PB_Window_SystemMenu) ;Create a window
  CreateGadgetList(WindowID(0)) ;tell PB you will add controls/gadgets
  ButtonGadget(2,200,100,50,25,"Test") ;add your button
  
  ;And now you get the what the user does in this loop
  Repeat
    EventID=WaitWindowEvent()
    
    Select EventID ;some event happends
      
      Case #PB_Event_Gadget ;it was a gadget
        Select EventGadget() ;lets find which gadget
          Case 2 ;was gadget 2, so lets do something when gadget 2 was clicked
            MessageRequester("","hello world!",0)
        EndSelect
        
    EndSelect
    
  Until EventID=#PB_Event_CloseWindow ;if closewindow is clicked
EndIf
End ; bye
Its very easy. Play with it, get used to it and very soon you will be moving like a fish in PureBasic.

I recommend the book, buy it.

Posted: Tue May 06, 2008 5:12 pm
by oToom
Hey up.

Just a another question, what sort of things does the book teach?
Most of the commands?

Posted: Tue May 06, 2008 7:04 pm
by rsts
If you download the 'sample' you can view the table of contents.

http://www.kalekold.net/pb-beginners/Re ... Sample.pdf

cheers

Posted: Tue May 06, 2008 9:17 pm
by Trond
In any case, PB is very uniformly built up, so that when you grasp how to use a few of the libraries, all that's really needed for the others is to read the help file.