[Gambas-user] gb.args

willy at ...3474... willy at ...3474...
Fri Nov 13 23:08:02 CET 2015


On 2015-11-13 11:55, Fabien Bodard wrote:
> Hi,
> 
> I've a big problem as i can't understand the gb.args usage.... even
> with the doc :-/
> 
> 
> Is there someone that can give me a tips ... or maybe this class must
> be rewritten.


Hi Fabien,

This is a code snippet (and accompanying  notes) from my application 
GambasLearning (an aid for people to learn Gambas).

The example is quite simple and a lot more can be done with arguments 
(like my app gbEdit (texteditor) allows opening files from commandline 
like this 'gbEdit mytext.txt'), but this should get you started in 
understanding how it works:

Notes:
Using gb.args it becomes easy to in for example a terminal do a
<yourappname> -V and get version returned without the application 
starting.
Both version and help are default in Gambas when adding gb.args 
component.
But how to add an argument?

This code snippet goes into a module that has been made startup class.
It adds 3 arguments to the application being:
-a (-> about)
-r (-> revison)
-s (->state)
When installed and started from menu the application will launch FMain
When installed and started from terminal without argument the 
application will
launch FMain
When run from terminal with arguments the application will not launch 
but return
the arguments information.

To test:
1. Open a new project (ArgTest) with a form FMain (no code needed)
2. Make a module named Start and make it starup class
3. Add the code below to the module start
4. Make a installation package
5. Install the installation package to your system
6. Start the application from menu (-> FMain should show)
6. Open a terminal and type ArgTest -a (-> should return about 
information and
NOT launch FMain)
7. In terminal type ArgTest -h (-> this will give you the list of 
arguments,
try them all)

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()
   If bA Then
     Print "Application to test gb.args\nBy W.J.L. Raets, The 
Netherlands"
   Else
     If bR Then
       Print "Rev. (#010)"
     Else
       If bS Then
         Print "Developer release"
       Else
         '--Start the main application--
         FMain.Show
       Endif
     Endif
   Endif

End

If you have any further questions just post me a mail.

gbWilly




More information about the User mailing list