BASIC anomaly or is it me?
Stephen Unwin (1516) 154 posts |
Hi, this is a section of code I’ve been working on and certain bit has me stumped! Following dropping a file in a window, I get a usermessage received in workspace% 559 : filepath2$=$(workspace%+44) 560 : REM byte bang as above doesn't work every time! 561 : filepath$="" 562 : temp1%=0 563 : temp2%=workspace%?44 564 : WHILE temp2%<>0 AND temp2%<>13 565 : filepath$+=CHR$temp2% 566 : temp1%+=1:temp2%=workspace%?(44+temp1%) 567 : ENDWHILE 568 : 569 : PROCseticontext (debug%,11,filepath$) 570 : PROCseticontext (debug%,12,filepath2$) *Edit I’ve Wimp_Initialiased the task with version 310 as those are the PRMs I’m working from. |
WPB (1391) 352 posts |
Probably the terminating character isn’t what the $ operator recognizes? Have a look at this: http://newsgroups.derkeiler.com/Archive/Comp/comp.sys.acorn.programmer/2010-04/msg00020.html |
Stephen Unwin (1516) 154 posts |
Ok, thanks for that. 599 : SYS"XOS_GenerateError",workspace%+44TOfilepath2$ Seems to work every time. When I was looking deeper into the bytes, the filepath string returned in workspace% was always terminated with a 0. I just couldn’t work out why it would work some of the time. |
WPB (1391) 352 posts |
No problem – glad that fixed it! ;) |
GavinWraith (26) 1563 posts |
In the days of the BBC B, strings were terminated by CR. After the Archimedes got going the importance of conformity with C, where strings are terminated by NUL, became more relevant. I think this is what explains much of the inconsistency about string-terminators in the RISC OS PRMs; though others may have more accurate memories than mine. It is for this reason that RiscLua offers a variety of ways of extracting strings from memory. Thus: $[x] – NUL-terminated string at x |
WPB (1391) 352 posts |
Gavin, while you’re here and I’m here, I have some questions about RiscLua that I emailed over to you the other day. Did you receive them? If not, pls email me on willblatchley [email symbol] yahoo [full-stop] com. Thanks! |
Steve Drain (222) 1620 posts |
String termination is quite a mess. NULL predominates, but LF is used in the Toolbox and just string length is used by some SWIs. And supplied strings can sometimes be control character terminated, but others must be NULL terminated. We will have to live with it, though.
Basalt has the RETURN$ keyword:
A RETURN$ statement will put a CR terminator to strings in situ. |