proc parameters

General development discussion.

Moderators: Susan Smith, admin, Gabriel

Post Reply
John
Posts: 555
Joined: Sun Apr 26, 2009 8:27 am

proc parameters

Post by John »

Is there a way to make a proc so that it can take parameters?

Here's what I'm thinking:

Currently I use a PROC ED from the br console to launch the associated .br.brs file in my preferred development program (n++). This has worked great for years now. I would like to be able to pass a line number so the ED proc file could open n++ on that line of the file. The only problem is I've never added an optional parameter to a proc and I'm not sure if it can be done.

Have you made a proc with an optional parameter? If so, how? And, would you mind sharing a small example?

John
John Bowman
mikemiller
Posts: 9
Joined: Wed Mar 17, 2021 6:01 am

Re: proc parameters

Post by mikemiller »

You can do so using the CHAIN statement.

As an example, in example.proc:

Code: Select all

PRINT 'Foo$ is equal to ' & Foo$ & '.'

And then in your calling program:

Code: Select all

0001 let Foo$ = 'bar'
0002 chain 'proc=example.proc', Foo$
Output:
Foo$ is equal to bar.
Gabriel
Posts: 408
Joined: Sun Aug 10, 2008 7:37 am
Location: Arlington, TX
Contact:

Re: proc parameters

Post by Gabriel »

There is a way to do it in procfiles too, but its a little tricky. Mikes technique might be more straight forward.

Maybe someone remembers it..

But it was something like you have an INPUT VAR1$, VAR2$ kind of statement in the beginning of the proc file. And then you call it but you redirect the parameters into it .. like you save the parameters in a display file with something like PRINT #1: "Value1", "Value2" and then you call the proc with <displayfile.txt

Does this ring a bell for anyone else?

At any rate, even best case thats still more complicated than Mikes solution so it probably doesn't matter if anyone remembers it or not! :)
mikemiller
Posts: 9
Joined: Wed Mar 17, 2021 6:01 am

Re: proc parameters

Post by mikemiller »

Just to add onto my prior example, a more realistic approach would be something like this.

ED PROC file:

Code: Select all

execute 'sys "C:\Program Files\NotePad++\NotePad++.exe"  '& SourceFile$ & ' -n' & Line$
Calling program:

Code: Select all

0001 let SourceFile$ = 'lib\myprogram.br.brs'
0002 let Line$ = '153'
0003 chain 'proc=ED', SourceFile$, Line$
This would open up the source file "lib\myprogram.br.brs" in N++ at line number 153.
gordon
Posts: 351
Joined: Fri Apr 24, 2009 6:02 pm

Re: proc parameters

Post by gordon »

I have the impression that John uses the PROC ED command to work around his preference to avoid using the EDITOR config statement because the EDIT command itself responds to a simple E command which can be accidently entered.

I also have the impression that John wants to be able to call N++ from the console to edit the current program and he has ED set to reference OS_FILENAME$(PROGRAM$) to identify the current program.

He just wants to optionally pass a line number as in PROC ED 12345. Not write a short program each time he calls N++. John it would have been good to attach your current ED file to your original post.

I suggest that an alternate (modified) ED proc (e.g. EDL) be used to simply prompt for a line number as in "LINPUT LN$" and extending the call to N++ with &" "&LN$.

John if I am off base on this please elaborate.
Post Reply