Args and namespaces

Post

Posted
Rating:
#1 (In Topic #1251)
Avatar
Trainee
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).

Code (gambas)

  1. ' Gambas module file
  2.  
  3. Public Sub Main()
  4.  
  5.    Dim bA, bR, bS As Boolean
  6.  
  7.    Args.Begin(Application.Name & " <option>")
  8.    bA = Args.Has("a", "about", "Display About " & Application.Name)
  9.    bR = Args.Has("r", "revision", "Display revision number")
  10.    bS = Args.Has("s", "state", "Display application state")
  11.    Args.End()
  12.  

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

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 :-)
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Trainee
As easy as that ... fantastic, thank you.
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’

BillyGoatGruff said

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 comp/src/gb.args/.src/Args.module · master · Gambas / gambas · GitLab file to your projects .src folder then you can modify it to your hearts content :)
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Trainee
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!
Online now: No Back to the top
1 guest and 0 members have just viewed this.