Welcome, Guest. Please login or register.

Author Topic: Blitz Basic: Reading arguments from the command line  (Read 2734 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show only replies by motorollin
Blitz Basic: Reading arguments from the command line
« 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
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10
 

Offline uncharted

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 1520
    • Show only replies by uncharted
Re: Blitz Basic: Reading arguments from the command line
« Reply #1 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.
 

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show only replies by motorollin
Re: Blitz Basic: Reading arguments from the command line
« Reply #2 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
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10
 

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show only replies by motorollin
Re: Blitz Basic: Reading arguments from the command line
« Reply #3 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
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10
 

Offline Doobrey

  • Hero Member
  • *****
  • Join Date: Oct 2002
  • Posts: 1876
    • Show only replies by Doobrey
    • http://www.doobreynet.co.uk
Re: Blitz Basic: Reading arguments from the command line
« Reply #4 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))
On schedule, and suing
 

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show only replies by motorollin
Re: Blitz Basic: Reading arguments from the command line
« Reply #5 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!!!
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10