New topic: 

Use of structures w/ mixed dta types in binary file i/o

<http://forums.realsoftware.com/viewtopic.php?t=29691>

       Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic         Author  
Message       dprowse           Post subject: Use of structures w/ mixed dta 
types in binary file i/oPosted: Sat Aug 22, 2009 7:32 pm                        
       
Joined: Wed Sep 26, 2007 11:02 am
Posts: 14              Hi, first time post. (edit: sorry...first post since 
upgrade from 2007r5 acdem to 2009r3 comm)

I am trying to use binary files for my data. I have a structure with one string 
parameter of 10 bytes and an integer as base test. I save off a single stucture 
like this:

Code:
dim MyData as aData
MyData.StrData = "word"
MyData.IntData = 10

Dim aBinaryStream as BinaryStream = 
GetFolderItem("data.dat").CreateBinaryFile("")
aBinaryStream.Write(MyData.StrData)

aBinaryStream.Close



File is created. Only string data is in file.

When I try to retreave data and set in static text like this:

Code:
dim aBinaryStream as BinaryStream = GetFolderItem("data.dat" 
).OpenAsBinaryFile(false )
dim MyData as aData
MyData.StringValue( aBinaryStream.LittleEndian ) = aBinaryStream.Read( 
MyData.Size )
text1.text = MyData.StrData

text2.text = str(MyData.IntData)



aData is the structure declared in a seperate module (public declare)
StrData as String * 10 (10 bytes)
IntData as Integer  (4 bytes)

The problem I am having, as I indecated, is that the int data isn't in the 
data.dat file. The data saved is the string data but only the chars in the 
string. In this case "word" with 6 bytes missing.

The int is not there.

I checked the Lang Ref and it seems to me (though I don't want to believe it) 
only string data can be saved. Is this true? Is there something I am missing? I 
had hoped to find an "IntegerValue..." to use but I couldn't see it.

I have a c++ background and am not sure how the translation would work. I am 
using Win on XP 32 for this. I am not overly familiar with rb.

Any thought?
Thanks in advance.
Derek      

    Last edited by dprowse on Sat Aug 22, 2009 8:18 pm, edited 1 time in total. 
  
                            Top               timhare           Post subject: 
Re: Use of structures w/ mixed dta types in binary file i/oPosted: Sat Aug 22, 
2009 7:42 pm                        
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6168
Location: Portland, OR  USA              You're only writing the string portion 
out.  Try writing it the same way you're reading it, using StringValue (not 
StrData).
Code:aBinaryStream.Write(MyData.StringValue)
Tim   
                            Top               dprowse           Post subject: 
Re: Use of structures w/ mixed dta types in binary file i/oPosted: Sat Aug 22, 
2009 8:20 pm                               
Joined: Wed Sep 26, 2007 11:02 am
Posts: 14              timhare wrote:You're only writing the string portion 
out.  Try writing it the same way you're reading it, using StringValue (not 
StrData).
Code:aBinaryStream.Write(MyData.StringValue)
Tim

Tried this but get error:

"This method requires more parameters than were passed" but can't find ref to 
other param refs. Thanks though.   
                            Top               npalardy           Post subject: 
Re: Use of structures w/ mixed dta types in binary file i/oPosted: Sat Aug 22, 
2009 10:26 pm                        
Joined: Sat Dec 24, 2005 8:18 pm
Posts: 5217
Location: Canada, Alberta, Near Red Deer              
Code:aBinaryStream.Write(MyData.StringValue(true or false (little endian) )
structures need to know if they should return string data as little endian     
_________________
My web site Great White Software
RBLibrary.com REALbasic learning  
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to