Hello JoeV,
It's neither MegaString, nor You
Your issue has to do with the DOC format and also the way MakeDoc builds the DOC file.
But you are right to use the MegaString for this kind of purpose.
The DOC format is a set of up to 4KB chunks of data, that are not CHR$(0) ended, when iziBasic works natively with chunks of data terminated with a CHR$(0) character.
Furthermore, in the DOC format, when a chunk maximum size is reached, the next character is to be found in the next chunk. Then, one of your strings will almost always be split between the end of a chunk and the beginning of the following chunk.
Add to this that MakeDoc does not write full 4KB chunks like other DOC tools (except the last chunk which is usually smaller than 4KB), but the size of each chunk is usually among 3KB to 4KB with MakeDoc.
Note: you may use Bird (or RsrcEdit) to see all of the above directly on your device, it is easier than to use an hex editor in the PC.
Knowing this you will understand what happens:
The INPUT$$ reads a 4KB chunk of data in the Palm memory. Then, it checks for a CHR$(0) and adjusts the following characters to CHR$(0) accordingly. And LEN$$ will then return the correct size. If no CHR$(0) character is found, the MegaString is believed to be 4KB big and... this is why the beginning of your MegaString is fed with what you expect to find and the last part of the chunk is filled with unexpected characters, these were the one stored in the Palm memory just after the ones you wanted to retrieve.
At this stage, what I suggest is the following (this is the easy way):
1. use TL-PDB to build your DOC file. This DOC editor will make sure that all but the last chunk of data are 4KB (4096 bytes) big
2. check with Bird what's the size of the last chunk
3. use the MegaString to read the chunks, one after the other (all but the last will be of 4096 bytes big, the last one you know from 2.), be careful with the change of chunk to correctly get the string split in between the 2 chunks
That should make it.
Another way of doing the job would be to build a PDB file, with many small records CHR$(0) terminated instead of a DOC file with LF separators among records. You would have more records but it would be easier to read and parse your file.
If you still have issues, don't hesitate to send me your code and the DOC file (I guarantee 100% confidentiality, all files will be deleted from my PC once the job will be done), I would give you a hand to finish this little coding with a DOC file.
Cheers,
@+
aldweb