Getting a list of keywords

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
User avatar
Median Joe
Posts: 15
Joined: Tuesday 8th November 2022 7:30pm
Location: Britain

Getting a list of keywords

Post by Median Joe »

I would like to print a list of all keywords, and according to the docs there is this function :
System.Keywords (gb.eval)
However, not sure how to use it. I guess I need to declare an array and write a loop, but all my attempts thus far have generated errors. Could someone kindly point me in the right direction?

Thanks!
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Getting a list of keywords

Post by vuott »

Hello,
you can use FOR...EACH...NEXT cycle:
Public Sub Main()

  Dim s As String

  For Each s In System.Keywords
    Print s
  Next

End
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
Median Joe
Posts: 15
Joined: Tuesday 8th November 2022 7:30pm
Location: Britain

Re: Getting a list of keywords

Post by Median Joe »

Thanks vuott,

I haven't quite got my head around how the Gambas object system works and was using the wrong syntax. I've always avoided OO languages until now and have only a hazy grasp of how OOP works, and all languages seem to implement it slightly differently.
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Getting a list of keywords

Post by vuott »

Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
Median Joe
Posts: 15
Joined: Tuesday 8th November 2022 7:30pm
Location: Britain

Re: Getting a list of keywords

Post by Median Joe »

Thanks for the links. I have started reading Gerry's book which is very good (thanks Gerry!), but I would prefer something more systematic. A Beginner's Guide to Gambas by John Rittinghouse is more comprehensive but it's pretty old. Anyone read it? I don't want to have to unlearn anything and there's a review on Amazon which says it's useless because it's mostly about version 2. Are newer versions of Gambas generally backwards compatible with older versions?
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Getting a list of keywords

Post by BruceSteers »

Median Joe wrote: Friday 11th November 2022 1:15pm Thanks vuott,

I haven't quite got my head around how the Gambas object system works and was using the wrong syntax. I've always avoided OO languages until now and have only a hazy grasp of how OOP works, and all languages seem to implement it slightly differently.
OOP rocks :)

you can do the same print out like this..
Print System.Keywords.Sort().Join("\n")
System.Keywords returns a String[] array so i use Sort() on that
Sort returns a sorted String[] array so i use Join("\n") on that to join the items with a newline so a single string.

Note: Keywords is a "property" and Sort() and Join() are functions so no brackets needed for Keywords but needed for Sort() and Join()

After typing a Keyword/function()/method()/property/etc then pressing the dot . the autocomplete shows all the properties/methods available.

This has been pretty much all the documentation I ever needed. I find it's kind of "learn as you go"
If at first you don't succeed , try doing something differently.
BruceS
User avatar
Median Joe
Posts: 15
Joined: Tuesday 8th November 2022 7:30pm
Location: Britain

Re: Getting a list of keywords

Post by Median Joe »

BruceSteers wrote: Friday 11th November 2022 5:57pm OOP rocks :)
All criticism of OOP (and there is a lot of it) seems to revolve around knowing when it's a appropriate to use it. It's a good fit for GUI, but maybe not other applications, like merging files or doing calculations for example. At least Gambas doesn't force OOP on you in all situations, as Java seems to.

Yes the built-in documentation is very good.
Post Reply