[Coco] DEF USR and strings?
William Astle
lost at l-w.ca
Wed Oct 29 17:03:37 EDT 2025
On 2025-10-29 14:48, Allen Huffman via Coco wrote:
> I could have swore I saw someone post (maybe on Facebook) that they realized the DEF USR could accept a string parameter. I had only known to use it like this:
>
> A$=“STRING”
> X=USR0(VARPTR(A$))
>
<snip>
> It looks like BEQ L8943 is where it goes if numeric, else it continues and gets the length and address of the string variable and continues.
>
> What is the syntax to make this work?
First, you leave out VARPTR completely. It's not needed if you rely on
USR to pass through a string parameter. (Under plain Color Basic, you
can't pass a string in but Extended Basic lets you).
The biggest problem is that if you pass a string to USRn(), VALTYP will
still be flagged as string when your USR routine returns and that will
trigger a TM error on the assignment (to X in your example). Your
handler routine will have to actually return a value instead of doing
nothing with a simple RTS. Note that if you do things right, your USRn()
handler can actually return a string but the how of that is beyond the
scope of this email.
If you get a TM error *with* the VARPTR in there, then you have
something else wrong.
More information about the Coco
mailing list