Passing args when CHAINing

Can anyone please explain how arguments are passed when CHAINing? The manuals give very poor instructions about chaining. My interpretation of what vague explanation is there is that the following should work:

Sending Program "send2aaa.tru":
LET x$="iuhsdjfnsdfj"
CHAIN "!C:\Windows\Temp\TBtest\aaa.exe" WITH (x$), RETURN
END

Target Program "aaa.tru":
PROGRAM send2aaa (x$)
print "x$=";x$
get key zz
END

In this very simple example, the Sending Program wants to pass x$ to the Target Program, which is supposed to print x$. The result is that the Target Program prints "x$= "; i.e., the value of x$ is not getting passed. The result is the same when either or both of these are redone as bound .exe's. Similarly when trying to send numeric x or arrays x$() and x(). And half the time a "no such file" error results, even when both are in the same directory. Doesn't seem to matter if Silver 5.33 or Gold 5.5b19.

Thanks for any help.

Mike C.

Comments

CHAINING

Hi,

I wrote about the chaining bug 34 weeks ago (see version 5 bugs).
I also wrote a correction for the manual at the same time, because the manual is very misleading - and has been for 20 years.

Basically you need to be very careful when using arg$ because chaining doesn't like spaces and doesn't like the keyword WITH. The new version 6 editor gets around the problem of spaces by replacing CHR$(32) with CHR$(31) prior to the chain command, and inside the chained program the arg$ are reprocessed to exchange CHR$(31) for CHR$(32). The TB editor also avoids problems with multiple arg$ by sending only one compound arg$ and splitting this up into multiple arg$ once the chained program is running.

Regards
Big John

re: passing variables via chain

This is a bit obscure.

1) The program you are chaining TO needs a PROGRAM statement as the first line of the program with the passed variables listed.

so in your example aaa.tru should have as the very first line (don't leave a blank line first)

PROGRAM aaa (x$)

The Chain statement in sendaaa.tru should now read

CHAIN "!C:\Windows\Temp\TBtest\aaa.exe "&x$, RETURN

being sure there is a space after the .exe.

That should now work--reply if it doesn't.

(Note: I think there is a 128 character limit to the full path name in the Chain command, but in your example that shouldn't be a problem. However, if you start making desktop shortcuts and using those to access deeply nested folders, you can easily exceed the 128 characters--Version 5.5 on eliminate this 128 character limit (present in he whole language in previous versions) but apparently the CHAIN command still retains that limitation.)

rwt

passing variables vis CHAIN

Dr. RWT,
Thanks for your very helpful reply.

The CHAIN statement you provided, using ["... .exe "&x$, RETURN] works for passing a single string var x$, in both Silver 5.33 and Gold 5.5b19. The sending program can be .TRU or .TXT but the receiver must be an .EXE. The following was also noted:

CHAIN "!C:\Windows\Temp\TBtest\aaa.exe "&(x$), RETURN ! with () also works. Can have more than one space after .exe. But if the one space is deleted, and then replaced: "no such file" error. Have to quit TB and reopen file.
CHAIN "!C:\Windows\Temp\TBtest\aaa.exe "WITH(x$), RETURN ! chains, but doesn't pass the arg.

However, when the programs are reconfigured for passing a numvar x=123.356, no construction of the CHAIN statement seems to work; neither the one you suggest nor the one in the manual's format:

LET x=123.456 ! This program is: Send2aaaX.tru
!CHAIN "!C:\Windows\Temp\TBtest\aaax.exe "&(x), RETURN ! error= "wrong type" at (x)
!CHAIN "!C:\Windows\Temp\TBtest\aaax.exe "&x, RETURN ! "wrong type" at x
!CHAIN "!C:\Windows\Temp\TBtest\aaax.exe "& x, RETURN ! "wrong type" at x
!CHAIN "!C:\Windows\Temp\TBtest\aaax.exe " & x, RETURN ! "wrong type" at x
!CHAIN "!C:\Windows\Temp\TBtest\aaax.exe" &(x), RETURN ! "wrong type" at (x)

! the following are more or less per p.229 of Gold manual, and don't work right:
!CHAIN "!C:\Windows\Temp\TBtest\aaax.exe " WITH (x), RETURN ! chained, arg not passed; same even w/o space
! after the .exe!
!CHAIN "!C:\Windows\Temp\TBtest\aaax.exe "WITH x, RETURN ! "Expected a "(" at x
!CHAIN "!C:\Windows\Temp\TBtest\aaax.exe " WITH(x), RETURN ! chains, but arg not passed
!CHAIN "!C:\Windows\Temp\TBtest\aaax.exe"WITH(x),RETURN ! chains, but arg not passed

! The receiving file is: aaax.exe:
! PROGRAM aaax (x)
! print "x=";x
! get key zz
! end
END

For two args, x1$ and x2$, neither of the following work:
CHAIN "!C:\Windows\Temp\TBtest\RECV2.EXE.exe "&(x1$,x2$), RETURN ! illegal expression at the comma
CHAIN "!C:\Windows\Temp\TBtest\RECV2.EXE.exe " WITH(x1$,x2$), RETURN ! "no such file (9003) 2 in main prog"

I could not get CHAIN to pass anything besides the one lone x$. Can you suggest the CHAIN statements which will allow the passing of say, x1,x2,x2...; x(); x1$,x2$,x3$...; and x$()? The formats prescribed in the manual do not work. The main problem seems to be getting the CHAIN statement into a form that TB will accept.
Thanks for your help.
Mike C.

multiple arguments--numerical arguments

here is a chain statement that I use.

CHAIN "!EFORCE\EFORCE2011.exe "&str$(menuflag)&" "&str$(anifactor),RETURN

You need to pass string variables, but you can convert numbers to strings as shown. Once passed however, these two numerical variables menuflag and anifactor are still numerical--you don't have to convert them back.

That is, the first line of EFORCE2011.exe is

PROGRAM EFORCE (menuflag,anifactor)

Note--the actual name after PROGRAM doesn't matter.

Also note in the CHAIN command the string space between the variables being passed but no other punctuation.

I haven't actually passed true string variables but assume the form (if I wanted to pass menuflag$ and anifactor$) would be

CHAIN "!EFORCE\EFORCE2011.exe "&menuflag$&" "&anifactor$,RETURN
PROGRAM EFORCE (menuflag$,anifactor$)

And yes, this stuff only works with executable programs.

Confusing and poorly documented to be sure. I wonder what the function of the exclamation point really is!

rwt

multiple arguments--numerical arguments

Yes. These work fine:
CHAIN "!C:\Windows\Temp\TBtest\aaax.exe "&str$(x), RETURN ! rtr's way: works

CHAIN "!C:\Windows\Temp\TBtest\aaTWO.exe "&str$(x)&" "&(u$), RETURN ! also works,
where target program is:

PROGRAM aaTWO (x,u$)
print "aaTWO rec'd: x=";x,"u$=";u$
get key zz
END

And now I see from BigJohn's post above that:

CHAIN filename$ arg1$ arg2$ should also work. Don't need the ampersands?

Now:
I found the following to work for passing STRING ARRAYS via CHAIN:
sending program:

DIM z$(10)
MAT READ z$
DATA z1,z2,z3,z4,z5,z6,z7,z8,z9,z10
CHAIN "!C:\Windows\Temp\TBtest\aaARR.exe "&(z$(a)), RETURN
! NOTE: the (a) can be any single letter or numeral, or series thereof, or mixed series thereof.
! e.g. a, U, a1d32c, 0, 1234, asdf, etc.
END
-------
target program:
PROGRAM aaARR (z$())
option nolet
uz=ubound (z$)
FOR i=1 TO uz
print i, z$(i)
NEXT i
print
END
----------

Thus I guess the only way to send a numarr is to first convert it to a strarr. Somewhat of a bother. But at least this much now works.

Thank you and BigJohn for all the help help.
Regards, Mike C.