Just started,

Just starting out? Need help? Post your questions and find answers here.
oToom
User
User
Posts: 54
Joined: Sat May 03, 2008 5:38 pm

Just started,

Post 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.
mrjiles
Enthusiast
Enthusiast
Posts: 238
Joined: Fri Aug 18, 2006 7:21 pm
Location: IL

Post by mrjiles »

PureBasic has a full network library available, so virtually anything network can be made.
oToom
User
User
Posts: 54
Joined: Sat May 03, 2008 5:38 pm

Post 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?
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post 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)
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
oToom
User
User
Posts: 54
Joined: Sat May 03, 2008 5:38 pm

Post by oToom »

This stuff seems quite hard at first sight.

Is it actually easier than it looks?
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

If you want a good place to start with Purebasic, my book is as good as any. :wink:
--Kale

Image
oToom
User
User
Posts: 54
Joined: Sat May 03, 2008 5:38 pm

Post 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.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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
--Kale

Image
oToom
User
User
Posts: 54
Joined: Sat May 03, 2008 5:38 pm

Post 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.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post 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.
oToom
User
User
Posts: 54
Joined: Sat May 03, 2008 5:38 pm

Post by oToom »

Hey up.

Just a another question, what sort of things does the book teach?
Most of the commands?
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

If you download the 'sample' you can view the table of contents.

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

cheers
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
Post Reply