How to line break

Greetings

I would like to write to text fields to a binary file. I use the below code example from Xojo. It writes the file, but it does not linebreak textfield 1 and 2. What does the code miss?

Thanks!

Ole


Dim f As FolderItem
Dim bs As BinaryStream

//get a folderitem
f = GetFolderItem(“Whole File”)

//create a binary file with the type of text (defined in the file types dialog)
bs = BinaryStream.Create(f, True)

//check to see if it was created
If bs <> Nil Then
bs.Write(TextField1.Text)
bs.Write(TextField2.Text)
//close the binaryStream
bs.Close
End If

bs.Write(TextField1.Text + EndOfLine)

Depending on the line break type you want, you can be more specific by doing EndOfLine.Windows, EndOfLine.Unix or EndOfLine.MacIntosh.

Thanks, Eli! :slight_smile:

So are you saying that there’s a difference, whether the program runs on Win or Mac?

Ole

Using the read example in Xojo, if I wanted to read the created file (with the 2 lines) and instead of having the output in the “OutputArea.Text”, place line 1 into textfield1 and line 2 into textfield 2… how could I do that?

Ole


Dim f As FolderItem
Dim bs As BinaryStream

//get a folderitem
f = GetFolderItem(“Whole File”)

//make sure it exists before we try to read it
If f.Exists Then

//open the folderitem as a binary file without write privelages
//     To open with write privelages, use true instead of false
bs = BinaryStream.Open(f, False)

//make sure we have a binary stream to read from
If bs <> Nil Then
  
  //read the whole binaryStream
  [b]OutputArea.Text = bs.Read(bs.Length)[/b]
  
  //close the binaryStream
  bs.Close
End If

End If

Write —

bs.writeDouble Len(textfield1.text)
bs.write textfield1.text
bs.writeDouble Len(textfield2.text)
bs.write textfield2.text

Read------
Dim tLen As Integer
TLen = bs.readDouble
Textfield1.text = bs.Read(TLen)
TLen = bs.readDouble
Textfield2.text = bs.Read(TLen)

If not unicode8, you will need to specify the encoding.

Thanks, Roger - will try this :slight_smile:

Ole