On Apr 4, 2006, at 5:15 PM, Joel Newport wrote:
When I read in the first 256 bytes of my file, the first byte is
missing.
Why would that be?
Here is my code.
Dim ReadFromFile as BinaryStream
Dim f as FolderItem
f=GetOpenFolderItem("")
oldHeader = newmemoryBlock(256)
If f <> Nil Then
ReadFromFile=f.OpenAsBinaryFile
oldHeader.stringValue(0,256) = readFromFile.read(256)
ReadFromFile.close
End If
editfield1.text = oldHeader.pString(0)
Sorry if it is obvious.
PString(i) interprets the bytes beginning at offset i as a Pascal
string. Such a string has the following format. The first byte
contains the length of the string data. The next bytes contain the
string data. In your code, PString(0) first reads the value of byte
0, which tells it the length of the string to read. It then grabs
the bytes following, copies them to a REALbasic String, and returns it.
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>