Args and namespaces

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
User avatar
BillyGoatGruff
Posts: 3
Joined: Sunday 2nd June 2024 1:33pm

Args and namespaces

Post by BillyGoatGruff »

Hi folks!

I'm using gb.Args as an example here, but I guess I'm primarily interested in how to correctly reference components (especially those supplied within the gb namespace). Pretty sure this is laid out somewhere in the wiki, but try as I might I cannot find the info I need (or I need more coffee).

' Gambas module file

Public Sub Main()

   Dim bA, bR, bS As Boolean

   Args.Begin(Application.Name & " <option>")
   bA = Args.Has("a", "about", "Display About " & Application.Name)
   bR = Args.Has("r", "revision", "Display revision number")
   bS = Args.Has("s", "state", "Display application state")
   Args.End()

End


Above is the entirety of my module file, a slightly reduced version of what I see over here. I don't expect it to do anything, because I removed the code that evaluates BA, bR etc, but I do expect it to compile, except what I get is the following error:

Code: Select all

Unknown symbol 'Begin' in class 'Args'
Do I need to import gb, or gb.Args and how do I do that? I also tried fully qualifying ("gb.Args.Begin") but that doesn't seem to help. A litte lost, would love a steer in the right direction :-)
User avatar
BruceSteers
Posts: 1624
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Args and namespaces

Post by BruceSteers »

You must open the project properties window and add the component gb.args

Once you have the component added then the additional Args functions will work.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BillyGoatGruff
Posts: 3
Joined: Sunday 2nd June 2024 1:33pm

Re: Args and namespaces

Post by BillyGoatGruff »

As easy as that ... fantastic, thank you.
User avatar
BruceSteers
Posts: 1624
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Args and namespaces

Post by BruceSteers »

BillyGoatGruff wrote: Sunday 2nd June 2024 3:31pm As easy as that ... fantastic, thank you.
You're welcome :)

It is possible to import gb.args and many other components/classes to your program but only do that if you need to modify the component to work differently than default.

For example some of my programs have imported gb.args that supports more than one char short names.
so something like -ab is treated as -ab and not both -a & -b

If you need a component to work differently you can simply import many of them into your project .src folder and remove the setting to load the gambas component.

So for gb.args it's a simple case of removing the gb.args from the project properties then copying the https://gitlab.com/gambas/gambas/-/blob ... rgs.module file to your projects .src folder then you can modify it to your hearts content :)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BillyGoatGruff
Posts: 3
Joined: Sunday 2nd June 2024 1:33pm

Re: Args and namespaces

Post by BillyGoatGruff »

I don't need to do anything like that currently, I'm really just exploring the language (and, I guess, the IDE) right now and gb.args is sufficient as-is (fwiw, though it doesn't really matter, my toy project I'm using as a learning vehicle is basically something of a re-implementation of cal/ncal but tailored a little to my own needs, and I wanted to parse various command line args as part of that). Still, that's a really useful insight, thank you!
Post Reply