Menu
JAQForum Ver 19.10.27

Forum Index : Microcontroller and PC projects : PicoMite BASIC MEMORY INPUT

Posted: 12:09pm
22 Mar 2026
Copy link to clipboard
Mark
Regular Member

I need help understanding the MEMORY INPUT command.

I have a data file that consists of an integer header followed by any number of fixed size blocks that my program needs to write and read.

I have a type defined for the block, but since the header is just an integer, I am trying to use MEMORY INPUT to read it and MEMORY PRINT to write it.  MEMORY PRINT works.

I use STRUCT SAVE and STRUCT LOAD after an appropriate SEEK to write and read the desired block and that works.

If the file consists of just the header with no blocks, such that it is only 8 bytes long, MEMORY INPUT works.  However, if the file has any blocks so that the length is greater than 8, MEMORY INPUT fails with and End of File error.


OPEN "File" FOR RANDOM AS #1
LOCAL I%
SEEK #1, 1
MEMORY INPUT #1, 8, PEEK(VARADDR, I%)


If I change my code and add a TYPE containing just an INTEGER, STRUCT LOAD works fine to read the header regardless of the file size.

----------------------

On a related question, what is the appropriate way to truncate a file?  Currently, I'm opening it for OUTPUT, then closing it, then opening it in RANDOM. The other option I see is to use KILL and ignore the error if the file didn't already exist.

Thanks,
Mark
 
Posted: 03:08pm
22 Mar 2026
Copy link to clipboard
toml_12953
Guru

  Mark said  
On a related question, what is the appropriate way to truncate a file?  Currently, I'm opening it for OUTPUT, then closing it, then opening it in RANDOM. The other option I see is to use KILL and ignore the error if the file didn't already exist.

Thanks,
Mark


Opening a file for RANDOM will create the file (with length 0) if it doesn't already exist. It doesn't cause an error. You can use KILL (make sure the file is closed, of course) then OPEN with RANDOM.
 
Posted: 03:15pm
22 Mar 2026
Copy link to clipboard
matherp
Guru

Mark
I think there is a bug, will look more.
 
Posted: 05:07pm
22 Mar 2026
Copy link to clipboard
Mark
Regular Member

Thanks for the replies.
 


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026