Write data from a memory bank to a file (or stream). |
bank = variable containing handle to valid bank filehandle|stream = a valid variable set with the WriteFile or OpenTCPStream (v1.52+) offset = offset in bytes to write the value count = how many bytes to write from the offset |
Command Description:
You can write the contents of a memory bank to a file on disk (or stream) using this command. Note: The file handle must be opened with WriteFile or OpenTCPStream and subsequently closed with CloseFile or CloseTCPStream after the writing operations are complete. Return how many bytes successfully written to a stream. Streams can only be used in Blitz Basic v1.52 or greater. |
Example:
; Read/WriteBytes Commands Example ; Create a 50 byte memory bank bnkTest=CreateBank(500) ; Let's fill the bank with crap For t = 1 To 50 PokeByte bnkTest,t,Rnd(255) PokeInt bnkTest,t+1,Rnd(10000) PokeShort bnkTest,t+2,Rnd(10000) PokeFloat bnkTest,t+3,Rnd(-.999,.999) Next ; Open a file to write to fileBank=WriteFile("test.bnk") ; Write the bank to the file WriteBytes bnkTest,fileBank,0,50 ; Close it CloseFile fileBank ; Free the bank FreeBank bnkTest ; Make a new one bnkTest=CreateBank(500) ; Open the file to read from fileBank=OpenFile("test.bnk") ; Write the bank to the file ReadBytes bnkTest,fileBank,0,50 ; Close it CloseFile fileBank ; Write back the results! For t = 1 To 50 Print PeekByte (bnkTest,t) Print PeekInt (bnkTest,t+1) Print PeekShort (bnkTest,t+2) Print PeekFloat (bnkTest,t+3) Next |