Getting specified section of text from a textfile
Richard Ashbery (495) 163 posts |
I can store a textfile into a memory buffer using SYS “OS_GBPB” or SYS “OS_File” as suggested previously by Steve and Fred which I can write to a TextArea gadget. Is there a way of writing a specified section of the text to the TextArea? |
Fred Graute (114) 645 posts |
Sure, as long as you can identify and extract the required section of text. To identify it you’ll need some kind of start marker, and to extract it you also need an end marker, eg end-of-line. One option might be to use a messages file. The start marker would then be a token which can be looked up using MessageTrans. Your code will then need to generate the token to extract on the fly. |
Richard Ashbery (495) 163 posts |
That sounds like a good idea Fred. It occurred to me that there might be a limit on the amount of data you could store in the Messages file. To simplify matters I wonder if I could do something similar with the built-in Messages utility in AppBasic. |
Steve Drain (222) 1620 posts |
A couple of caveats occur to me. First, a MessageTrans string ends with LF (10) if you use the direct pointer to it. That will not work with a TextArea, which requires a NUL (0), as discussed earlier. I have been there and done that once – filling the TextArea with endless, unwanted text. ;-) Second, if you use the AppBasic Messages utility, your text will be limited to a BASIC string of 255 characters, and you will still have to provide the NUL terminator. Also, that utility only works with the application Messages file, which will probably be unsuitable. This means you will have to provide a buffer for the text to MessageTrans_Lookup and use the pointer to it for the TextArea. Not difficult, but not provided for in AppBasic, I think. You can guess that I have ways to do it with Basalt, but can you be more specific about the nature of what you want to display? Is it related to the Database topic you posted about? |
Fred Graute (114) 645 posts |
True, but if the messages file is in the RMA you can temporarily replace the LF with NUL, transfer the text to the TextArea then reinstate the LF. MessageTrans_Lookup returns the size of the result so this should be quite easy.
AppBasic provides support for both string and block transfers so the size of the text shouldn’t be an issue. |
Steve Drain (222) 1620 posts |
Yes. That was a possible solution to the original problem, before Messages files were involved. I have done something similar to make Messages strings readable as BASIC strings.
I am probably looking at too old a version of AB. Sorry. |