[Coco] DEF USR and strings?
Allen Huffman
alsplace at pobox.com
Wed Oct 29 17:41:28 EDT 2025
> On Oct 29, 2025, at 4:03 PM, William Astle via Coco <coco at maltedmedia.com> wrote:
>
> 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.
It looks like I tried this back in 2017 and couldn’t get it to work:
https://subethasoftware.com/2017/02/07/interfacing-assembly-with-basic-via-defusr-part-3/
There, I wrote:
"Unfortunately, the USRx() command only allows you to pass in a numeric value, and not a string, so we can’t simply do something like:
A$=USR0("Convert this to all uppercase.") 'THIS WILL NOT WORK!
I suspect my handling of USRx may be incorrect? I am pretty sure I did not know this was even possible until I saw someone post about it working, somewhere.
— Allen
More information about the Coco
mailing list