Donate Now Goal amount for this month: 100 USD, Received: 0 USD (0%)
Donate to support this site and ThinBASIC project development

Results 1 to 5 of 5

Thread: Passing Arguments To Tbasic Program

  1. #1
    Member
    Join Date
    Jul 2010
    Location
    Phoenix, Arizona, usa
    Age
    64
    Posts
    54
    Rep Power
    10

    Passing Arguments To Tbasic Program

    How do I pass arguments to a thinbasic program?
    Specifically how do I access the argument values that
    I pass to a thinbasic program?

    For example I want to pass the two arguments 3.14 and 1.717
    to the thinbasic program myprog.bas as follows:

    thinbasic myprog.bas 3.14 1.717


    1. Is passing arguments even possible in this way?

    2. How do I access these argument values within myprog.bas

    Thanks for any help.

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,409
    Rep Power
    650
    Interesting question,

    I think lot of people would like to do this ... and it is possible

    This functionality is handled by OS module, by functions:
    • OS_GetCommand
    • OS_GetCommands
    • OS_CommandPresent
    • OS_CommandsGetSep
    • OS_CommandsSetSep

    You can read more about them in the help file + see the sample code thinBasic\SampleScripts\OS\OS_SampleCommandLine.tBasic.

    Here more elemental example to handle your task:
    Uses "OS" ' -- For command line handling
    Uses "Console"
    
    Long i
    
    ' -- When launched from thinAir, the first param is @1 and the second name of the script
    ' -- When launched independently, the first param is name of the script
    For i = 1 To OS_GetCommands
      PrintL "Parameter #"+Format$(i), OS_GetCommand(i)
      PrintL
    Next
                                                
    ' -- Because of this behavior, the parameters we need are the prev-to-last and last one                                            
    Single param1 = OS_GetCommand(OS_GetCommands-1)
    Single param2 = OS_GetCommand(OS_GetCommands)                                          
    
    MsgBox 0, "Number #1 = " + Format$(param1) + $CRLF + 
              "Number #2 = " + Format$(param2) 
    WaitKey
    
    To test how it works, simply enter this in ThinAir, and then click Script/Command line and enter the two numbers separated by space.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  3. #3
    Member
    Join Date
    Jul 2010
    Location
    Phoenix, Arizona, usa
    Age
    64
    Posts
    54
    Rep Power
    10

    Thanks That Did The Trick

    Thanks Petr.

    That works.



  4. #4
    Member
    Join Date
    Jul 2010
    Location
    Phoenix, Arizona, usa
    Age
    64
    Posts
    54
    Rep Power
    10

    argument being split

    I was trying to pass the arguments 1e-9 and 10e-9
    but the program splits 1e-9 into 1e and -9.
    Can I control the separator characters?

    My command line is:

    thinbasic vt.bas mosdata1.txt 1e-9 10e-9


    ================
    Answer: To use spaces as the separator character use the following program line

    OS_CommandsSetSep(" ")

    before using the functions OS_GetCommands and OS_GetCommand()

    ( I include this post in case others run into this problem. )

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,409
    Rep Power
    650
    Thanks for sharing the solution!


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

Similar Threads

  1. Invoking One .tbasic Program From Another .tbasic Program
    By gungadout in forum thinBasic General
    Replies: 46
    Last Post: 23-11-2009, 12:01
  2. difference between .tbasic and .tbasicc
    By sandyrepope in forum Console
    Replies: 4
    Last Post: 22-05-2008, 23:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •