[quote="sinner"]
L.AddRow Stream.ReadPString
The use of PString limits you to 255 characters of data
Avoiding that use and making the write write a int32 that is the count then the bytes would let you put as much data as you want
Also you probably need to know the encoding of the data you write & read
I've adjusted things as suggested (but this is entirely written in the forum so it's not tested)
But it should give you the idea
Sub SaveData( L As ListBox )
Dim i,x As integer
Dim Stream As BinaryStream
Dim f As FolderItem = New FolderItem( "C:\DataFile" , FolderItem.PathTypeShell )
if f <> NIL Then
Stream=f.CreateBinaryFile(".data")
Stream.WriteLong L.ListCount
Stream.WriteLong L.ColumnCount
For i = 0 To L.ListCount-1
For x = 0 To L.ColumnCount-1
dim data as string = ConvertEncoding( L.Cell( i , x ), Encodings.UTF8 )
Stream.WriteInt32 lenB(data) // yes LenB as you need to know how many bytes you write
Stream.Write data
Next
Next
Stream.Close
End
End Sub
Sub LoadData( L As ListBox )
Dim Stream As BinaryStream
Dim Count1,Count2,i,x As Integer
Dim f As folderitem= GetFolderItem("C:\DataFile", FolderItem.PathTypeShell )
If f.Exists Then
If f = Nil Then Exit
Stream = f.OpenAsBinaryFile(False)
Count1 = Stream.ReadLong
Count2 = Stream.ReadLong
For i = 0 To Count1-1
L.AddRow Stream.ReadPString
For x = 1 To Count2-1
dim readLen as Int32 = Stream.ReadInt32
L.Cell( i , x ) = Stream.Read( readLen, Encodings.UTF8 )
Next
Next
Stream.Close
End
End Sub
The other thing you might want to do is pass in the folderitem to read from / write to as a parameter