Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 04:31 23 Mar 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

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

Author Message
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 91
Posted: 12:09pm 22 Mar 2026
Copy link to clipboard 
Print this post

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
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 572
Posted: 03:08pm 22 Mar 2026
Copy link to clipboard 
Print this post

  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.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11099
Posted: 03:15pm 22 Mar 2026
Copy link to clipboard 
Print this post

Mark
I think there is a bug, will look more.
 
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 91
Posted: 05:07pm 22 Mar 2026
Copy link to clipboard 
Print this post

Thanks for the replies.
 
Print this page


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