A Hello and a Question

Everything else that doesn't fall into one of the other PB categories.
TwoCatsYelling
User
User
Posts: 20
Joined: Thu Mar 18, 2021 6:26 pm

A Hello and a Question

Post 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!
Last edited by TwoCatsYelling on Thu Mar 18, 2021 8:27 pm, edited 1 time in total.
Bitblazer
Enthusiast
Enthusiast
Posts: 762
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: A Hello and a Question

Post 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 :)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: A Hello and a Question

Post 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
ImageThe happiness is a road...
Not a destination
User avatar
Shardik
Addict
Addict
Posts: 2062
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: A Hello and a Question

Post 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"
TwoCatsYelling
User
User
Posts: 20
Joined: Thu Mar 18, 2021 6:26 pm

Re: A Hello and a Question

Post 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!
TwoCatsYelling
User
User
Posts: 20
Joined: Thu Mar 18, 2021 6:26 pm

Re: A Hello and a Question

Post 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!
TwoCatsYelling
User
User
Posts: 20
Joined: Thu Mar 18, 2021 6:26 pm

Re: A Hello and a Question

Post 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!
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: A Hello and a Question

Post 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
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
TwoCatsYelling
User
User
Posts: 20
Joined: Thu Mar 18, 2021 6:26 pm

Re: A Hello and a Question

Post 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.
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: A Hello and a Question

Post 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.
Last edited by TI-994A on Tue Mar 23, 2021 1:16 pm, edited 1 time in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Axolotl
Addict
Addict
Posts: 865
Joined: Wed Dec 31, 2008 3:36 pm

Re: A Hello and a Question

Post 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:
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: A Hello and a Question

Post 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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply