Hi Peter,
I hope that I'm allowed to answer as you asked Eros specifically. The FILE module stores binary files as strings. But you can do what you want to do with thinBasic. You just have to use some conversion commands. Look in the helpfile under the MKx commands for your write activities and the CVx commands for when you read. But here are some functions to get you started:
[code=thinbasic]
'------------------------------------------------------------
SUB FileWriteInt( f AS DWORD, i AS INTEGER )
FILE_PUT( f, MKI$( i ))
END SUB
'------------------------------------------------------------
SUB FileWriteLong( f AS DWORD, l AS LONG )
FILE_PUT( f, MKL$( l ))
END SUB
'------------------------------------------------------------
SUB FileWriteSingle( f AS DWORD, s AS SINGLE )
FILE_PUT( f, MKS$( s ))
END SUB
'------------------------------------------------------------
SUB FileWriteByte( f AS DWORD, b as byte)
FILE_PUT( f, MKbyt$( b ))
End SUB
'------------------------------------------------------------
sub FileWriteString( f AS DWORD, s as string )
local ch as byte
local k as long
For k = 1 To Len( s )
ch=Asc(Mid$(s,k,1))
FileWriteByte(f,ch)
If ch=0 then exit for
Next
FileWriteByte( f, 0 )
End sub
'------------------------------------------------------------
FUNCTION FileReadByte( f AS DWORD ) AS byte
DIM b AS byte
DIM buffer AS STRING
buffer = FILE_GET( f, 1 )
b = CVbyt( buffer, 1 )
RETURN b
END FUNCTION
'------------------------------------------------------------
FUNCTION FileReadInt( f AS DWORD ) AS INTEGER
DIM i AS INTEGER
DIM buffer AS STRING
buffer = FILE_GET( f, 2 )
i = CVI( buffer, 1 )
RETURN i
END FUNCTION
'------------------------------------------------------------
FUNCTION FileReadLong( f AS DWORD ) AS LONG
DIM l AS LONG
DIM buffer AS STRING
buffer = FILE_GET( f, 4 )
l = CVL( buffer, 1 )
RETURN l
END FUNCTION
'------------------------------------------------------------
FUNCTION FileReadSingle( f AS DWORD ) AS SINGLE
DIM s AS SINGLE
DIM buffer AS STRING
buffer = FILE_GET( f, 4 )
s = CVS( buffer, 1 )
RETURN s
END FUNCTION
'------------------------------------------------------------
Function FileReadString( f as dword ) as string
local s as string
local ch as byte
do
ch=fileReadByte( f )
If ch=0 then exit do
s = s + Chr$(ch)
loop
return s
End Function
[/code]
I hope that helps
Michael
Bookmarks