Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: motorollin on May 26, 2006, 08:01:14 AM

Title: Blitz Basic: Reading arguments from the command line
Post by: motorollin on May 26, 2006, 08:01:14 AM
I've scoured the Blitz manual and searched online but I can't find an answer to this... How on earth do I read command line arguments from Blitz?

--
moto
Title: Re: Blitz Basic: Reading arguments from the command line
Post by: uncharted on May 26, 2006, 09:30:39 AM
From the manual (about page 129)...

Quote

- NumPars

The  NumPars  function  allows an executable  file  to  determine  how  many
parameters  were  passed to it by either Workbench or the  CLI.   Parameters
passed  from  the CLI are typed following the program name and separated  by
spaces.

For example. Iet's say you have created an executable program called myprog,
and run it trom the CLI in the following way:

myprog filer Olle2

In  this  case,  NumPars would return the value '2' - 'file I ' and  'file2'
beng the 2 parameters.

Programs  run  from  Workbench are only capable of picking  up  I  parameter
through the use of either the parameter file's 'Default Tool' entry in  it's
'.info' file, or by use of multiple selection through the 'Shift' key.

If no parameters are supplied to an executable file,  NumPars will return 0.
During program development,  the 'CLI Arguement' menu item in the 'COMPILER'
menu allows you to test out CLI parameters.

Par$ (Parameter)

Par$ return a striny equivalent to a parameter passed to an executable  file
through  either  the CLI or Workbench.  Please refer  to  NumPars  for  more
information on parameter passiny.


FromCLI

Returns TRUE (-1)  if your program was run from the CLI, or FALSE (O) if run
from the WorkBench.

ParPath$ (parameter,type)

ParPath$  returns the path that the parameter resides in,  'type'  specifies
how you want the path returned:

0  You  want only the directory of the parameter returned.  1   You  want  the
directory along with the parameter name returned.

If you passed the parameter "FRED" to your program from WorkBench,  and FRED
resides  in  the  directory   "work:mystuff/myprograms"  then  ParPath$(0,0)
willreturn  "work:mystuff/myprograms",    but   ParPath$(0,1)   will  return
"work:mystuff/myprograms/FRED".

The  way WB handles argument passing of directories is different to that  of
files.   When a directory is passed as an argument,  ArgsLib gets  an  empty
string for the name,  and the directory string holds the path to the  passed
directory AND the directory name itself.


Hope this is useful.
Title: Re: Blitz Basic: Reading arguments from the command line
Post by: motorollin on May 26, 2006, 07:06:26 PM
Thanks! I didn't think of searching the document for "parameter" :roll: I guess the command I'm looking for is "par$(parameter)". So if I ran the programme like this:

1.>myprog arg1=value

Then the command "str$=par$(arg1)" would set the variable str$ to "value". Right???

Thanks

--
moto
Title: Re: Blitz Basic: Reading arguments from the command line
Post by: motorollin on May 26, 2006, 08:00:32 PM
Ok, got it working by using "b$=Par$(1)". Now, is there any way to convert the string variable b$ to a byte variable so I can pass it to the parallel port?

--
moto
Title: Re: Blitz Basic: Reading arguments from the command line
Post by: Doobrey on May 26, 2006, 08:08:35 PM
Try the Val command, it converts a numeric string to an integar.

eg. my_number.b=Val(Par$(1))
Title: Re: Blitz Basic: Reading arguments from the command line
Post by: motorollin on May 26, 2006, 08:27:40 PM
That works - thanks! :-) I had to add a "%" to the beginning of the string, but then it worked.

When I create an executable from the "Compiler" menu and then run the programme from the shell, it doesn't do anything. The relays don't change. If I run it inside Blitz then it works. Why might this be?

--
moto

--EDIT
Forget that, I think I just had to close the Blitz editor as it was hogging the port. It's all working now  :-D  :-D  :-D  Thanks a lot for your help guys!!!