Page 1 of 1

A Hello and a Question

Posted: Thu Mar 18, 2021 6:36 pm
by TwoCatsYelling
Hi all,

My TwoCatsYelling (you can call me Cats :p). New to PureBasic; just purchased my copy earlier today. I'm eager to jump in and learn!

I'm very new to programming. Have tried a variety of languages, followed some introductory tutorials, and learned the basics (variables, functions, etc). Long story short, I found my way to looking into BASIC, and then found PureBasic, and here I am.

So!

Something I haven't found, yet, are introductory tutorials. The ones I've found jump straight into programming applications that I think would be a bit beyond me at this point (the image viewer, and snake game). Other languages I've looked into have a series of videos that give a more formal introduction to the language structure and such, usually including some basic programs to show how things work, etc. Haven't been able to find anything like that for this, though.

So I was wondering if anyone can point to some good, basic tutorials, to at least get me rolling in the right direction?

Thanks a bunch!

Re: A Hello and a Question

Posted: Thu Mar 18, 2021 7:09 pm
by Bitblazer
Hello Cats and welcome to PureBasic!

There are many resources and you could look >> here << for example. Click the Tutorials button. There are even free beginner books :)

Re: A Hello and a Question

Posted: Thu Mar 18, 2021 7:14 pm
by Kwai chang caine
Or here in your sofa, to see good movies on your TV with popcorns :mrgreen:
https://www.youtube.com/channel/UCseEtp ... j4w-MDbhDw

Re: A Hello and a Question

Posted: Thu Mar 18, 2021 8:09 pm
by Shardik
You may take a look into "We start programming".

Or you may even download a complete book about PureBasic:
"PureBasic - A Beginner's Guide To Computer Programming"

Re: A Hello and a Question

Posted: Thu Mar 18, 2021 8:29 pm
by TwoCatsYelling
Shardik wrote:You may take a look into "We start programming".

Or you may even download a complete book about PureBasic:
"PureBasic - A Beginner's Guide To Computer Programming"
I did find that book (after I posted the message... of course!), but I did not know about the "We Start Programming", so I have that bookmarked, too. At a glimpse, that looks like exactly what I was looking for.

Thanks!

Re: A Hello and a Question

Posted: Thu Mar 18, 2021 8:30 pm
by TwoCatsYelling
Kwai chang caine wrote:Or here in your sofa, to see good movies on your TV with popcorns :mrgreen:
https://www.youtube.com/channel/UCseEtp ... j4w-MDbhDw
Hello!

I started going through some of those videos and then realized they seemed a bit beyond me at this point. But I'm definitely going to return to them when I feel more familiar with the language. This way I can follow along and better understand what he's doing.

Thanks!

Re: A Hello and a Question

Posted: Thu Mar 18, 2021 8:31 pm
by TwoCatsYelling
Bitblazer wrote:Hello Cats and welcome to PureBasic!

There are many resources and you could look >> here << for example. Click the Tutorials button. There are even free beginner books :)
Well that's a treasure trove!

I wish that had come up in my searching. Gonna bookmark and dive right into that.

Thanks!

Re: A Hello and a Question

Posted: Fri Mar 19, 2021 12:21 am
by TI-994A
TwoCatsYelling wrote:...some good, basic tutorials, to at least get me rolling in the right direction?
This might be a good start:

> The Basic Anatomy of a PureBasic Program

Re: A Hello and a Question

Posted: Tue Mar 23, 2021 12:07 am
by TwoCatsYelling
TI-994A wrote:
TwoCatsYelling wrote:...some good, basic tutorials, to at least get me rolling in the right direction?
This might be a good start:

> The Basic Anatomy of a PureBasic Program
Thank you!

I followed it fine up 'til the very end, where we create the form version of the window, to grab the text from the Text field and place it in the Label field.
The button doesn't do anything when I click on it.

I double-checked, and even copied and pasted their exact code, with the same results. Also, one of the options they instruct to set in the form preferences wasn't there. So, I'm guessing it's another case of something changing in the language since that was written (almost 6 years is a long time). The the non-form version of it worked fine.

That's okay though. I don't intend to be using forms just yet. So, when I get to that, I'll figure out how it should work.

Re: A Hello and a Question

Posted: Tue Mar 23, 2021 8:24 am
by TI-994A
TwoCatsYelling wrote:... The button doesn't do anything when I click on it.
In the code (from this tutorial), clicking the button will change the label text to the string entered in the text box.

* Enter some text into the empty StringGadget() > Press the ButtonGadget() labelled "Click Me" > The content of the TextGadget() changes to the input text.

Code: Select all

wFlags = #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget |
         #PB_Window_SizeGadget | #PB_Window_ScreenCentered

OpenWindow(0, 0, 0, 300, 200, "My Window", wFlags)
TextGadget(1, 50, 30, 200, 30, "This is a label...")
StringGadget(2, 50, 70, 200, 30, "")
ButtonGadget(3, 50, 120, 200, 30, "Click Me")

Repeat
  event = WaitWindowEvent()
  If event = #PB_Event_Gadget
    gadget = EventGadget()
   
    ;if the button is pressed (identifier = 3)
    If gadget = 3
     
      ;get the text from the text box (identifier = 2)
      text$ = GetGadgetText(2)
     
      ;and place it in the label (identifier = 1)
      SetGadgetText(1, text$)
     
    EndIf
  EndIf
Until event = #PB_Event_CloseWindow
TwoCatsYelling wrote:... Also, one of the options they instruct to set in the form preferences wasn't there. So, I'm guessing it's another case of something changing in the language since that was written (almost 6 years is a long time).
Yes. That form option was removed about a year after the tutorial was posted.
PureBasic Manual - History wrote:1st March 2016 : Version 5.42 LTS
- Removed: 'generate event loop' option in the Preferences/Form

Essentially, by selecting that option, the following event loop would be generated within the form code, along with the call to the OpenWindow_0() procedure:

Code: Select all

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False
Since there will be no event loop generated in the form code now, it should be included in the external code file. So, the code in Section 10 of the tutorial, which currently looks like this:

MyFormEvents.pb

Code: Select all

XIncludeFile "MyForm.pbf"

Procedure buttonEvent(eventType.i)
  ;get the text from the text box (identifier = String_0)
  text$ = GetGadgetText(String_0)
 
  ;and place it in the label (identifier = Text_0)
  SetGadgetText(Text_0, text$) 
EndProcedure
...should now look like this:

MyFormEvents.pb

Code: Select all

XIncludeFile "MyForm.pbf"

Procedure buttonEvent(eventType.i)
  ;get the text from the text box (identifier = String_0)
  text$ = GetGadgetText(String_0)
 
  ;and place it in the label (identifier = Text_0)
  SetGadgetText(Text_0, text$) 
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False
Thank you for highlighting these changes. The tutorial shall be amended accordingly.

Re: A Hello and a Question

Posted: Tue Mar 23, 2021 1:03 pm
by Axolotl
@TI-994A
maybe this line

Code: Select all

  If #PB_Event_Gadget
should be changed to

Code: Select all

  If event = #PB_Event_Gadget
:oops:

Re: A Hello and a Question

Posted: Tue Mar 23, 2021 1:14 pm
by TI-994A
Axolotl wrote:...should be changed to

Code: Select all

  If event = #PB_Event_Gadget
Good catch! The code was originally adapted from a Select/Case block, and the event check was clearly missed. It's a fluke that the logic works. Thank you.