I returned to this and made some minor changes, and am now stuck on this error:
Cannot convert _OFFSET type to other types on line 118.
Caused by (or after): IF ( GETRAWINPUTDEVICELIST ( MYLIST , MYADDR , MEM . SIZE ) <> 0 ) THEN
This is probably outside the scope of this thread, so I'll start a new one for this, related to type "_OFFSET".