Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_memput/get from file.
#3
(09-19-2025, 08:10 PM)SMcNeill Wrote: Are new keywords really needed?  Something like this is so simple, just write a quick set of functions, add it to your toolbox and be done with it.

Code: (Select All)
Dim Astring As String * 20

Open "temp.txt" For Output As #1 'create a file
For i = 1 To 20
    Astring = "Hello World # " + _ToStr$(i)
    Print #1, Astring;
Next
Close
Print "File created, now to test -- press any key:"
Sleep


'Now for some quick testing:
Dim foo As _MEM
MemOpenfile "temp.txt", foo 'get the file into mem

For i = 0 To 19
    _MemGet foo, foo.OFFSET + i * 20, Astring
    Print Astring
Next

For i = 0 To 19 'rewrite the data and put to mem
    Astring = "Steve is Amazing " + _ToStr$(i + 1)
    _MemPut foo, foo.OFFSET + 20 * i, Astring
Next

MemSaveFile foo, "temp2.txt" 'save the mem into to a file

Print "File loaded, displayed, changed, and saved as temp2.txt."
Print "Press "
Sleep

Open "temp2.txt" For Binary As #1
For i = 1 To 20
    Get #1, , Astring
    Print Astring
Next
Close

Sub MemOpenfile (file$, m As _MEM)
    Dim temp As String
    temp$ = _ReadFile$(file$)
    m = _MemNew(Len(temp$))
    _MemPut m, m.OFFSET, temp$
End Sub

Sub MemSaveFile (m As _MEM, file$)
    Dim temp As String
    temp = Space$(m.SIZE)
    _MemGet m, m.OFFSET, temp
    _WriteFile file$, temp
End Sub

   That's easy enough.   But my thought was also that a builtin function might also be a bit closer to the metal and thus faster.    It's not really a big deal to me TBH.
But I do get ideas I need to throw out there from time to time !.
Reply


Messages In This Thread
_memput/get from file. - by ahenry3068 - 09-19-2025, 07:43 PM
RE: _memput/get from file. - by SMcNeill - 09-19-2025, 08:10 PM
RE: _memput/get from file. - by ahenry3068 - 09-19-2025, 08:22 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)