AppGameKit has 2 Functions.,
OpenToWrite( FileID, FileName$ )
OpenToRead( FileID, FileName$ )
Now personally I'd prefer the Function to simply be "OpenFile"., because you're actually more limited when Writing than Reading.
For example., when you're Writing to a File you HAVE to specify where you want to Start Writing in the File (be it at the Start, or an Offset) ... the SetFilePos( ) and GetFilePos( ) Functions while not part of the "Read File" Section; are ONLY usable if the File is Opened to be Read.
The other frustration of this, is that in Order to Read/Write to a File; you HAVE to constantly Open and Close the File for the specific Operations.
A better alternative to this is using a Memory Block (Memblock) to Create / Manipulate the Data.
This can be done with the Memblock Functions:
CreateFileFromMemblock( FileName$, MemblockID )
CreateMemblockFromFile( MemblockID, FileName$ )
Data Manipulation is much easier and you can do R+W rather R/W Operations via Memblocks... but there are some downsides to this.
First is Performance.
Memblocks are MUCH Slower ... there is an irony here that in Dark BASIC Classic we used to have lengthy discussions about the very same drawbacks.
The other issue is that Memblocks use a Fixed Size., so if you want to expand what Data you have then you HAVE to create a Second Memblock that's Larger and Transfer across all the Data; or obviously switch to the File Commands, as those are only limited to 4GB; which should be more than enough outside of some select situations.
Now a way around this., and I used to use this method in Dark BASIC Classic is to create a "Save Block"... akin to how Console Memory Cards used to work.
In this regard you'd always know the size and at least one of the downsides of Memory Blocks was eliminated; as they'd always be the same generic size.
MemID As Integer = 0
MemID = CreateMemblock( 4 * 10 )
Data As Integer = 1
For Position = 0 To 9
Inc Data, Data + Data
SetMemblockInt( MemID, Position * 4, Data )
Next
CreateFileFromMemblock( "Example.File", MemID )
DeleteMemblock( MemID )
MemID = CreateMemblockFromFile( "Example.File" )
Repeat
For Position = 0 To 9
Data = GetMemblockInt( MemID, Position * 4 )
Print( Data )
Next
Print( "Press Space to Continue..." )
Sync()
Until GetRawKeyState( 32 )
DeleteMemblock( MemID )
DeleteFile( "Example.File" )
FileID As Integer = 0
FileID = OpenToWrite( "Example.File" )
Data = 1
For Position = 0 To 9
Inc Data, Data + Round( Data * 0.5 )
WriteInteger( FileID, Data )
Next
CloseFile(FileID)
FileID = OpenToRead( "Example.File")
Repeat
SetFilePos( FileID, 0 )
For Position = 0 To 9
Data = ReadInteger( FileID )
Print( Data )
Next
Print( "Press Escape to Exit" )
Sync()
Until GetRawKeyState( 27 )
CloseFile( FileID )
DeleteFile( "Example.File" )