Open and save muliple textfield

I am making a desktop app
There are 3 text Area to write different text but when save and then open text area contain same text together.

For Example :
Text Area 1 >> qwert
Text Area 2 >> yuiop
Text Area 3 >> asdfg

But when I open after saving, all Text Field contain same text >> qwertyuiopasdfg

How can I Save this problem please help

It really depends on what your code looks like for saving and reading. It should be something like

// save the info
outstream.WriteLine TextArea1.Text
outstream.WriteLine TextArea2.Text
outstream.WriteLine TextArea3.Text
// read the info
TextArea1.Text = instream.ReadLine
TextArea2.Text = instream.ReadLine
TextArea3.Text = instream.ReadLine

This is a very crude way to do it. It works, but is rather fragile. You could expand on it by writing key/value pairs, or even using a database.

I tried this but only one line is showing in each text area.

Please post the code you use for saving.

1 Like


// read the info
TextArea1.Text = instream.ReadLine + EndOfLine
TextArea2.Text = instream.ReadLine + EndOfLine
TextArea3.Text = instream.ReadLine + EndOfLine

if you have multiline text better save the len before and later read the string with this count.
or try to load/save as json.

For opening,

var FileDialog As FolderItem
FileDialog = FolderItem.ShowOpenFileDialog(“text/plain”)

if FileDialog <> nil then
var UserSelect As TextInputStream
UserSelect = TextInputStream.Open(FileDialog)
UserSelect.Encoding = Encodings.UTF8

var ReadData As String
ReadData = UserSelect.ReadAll()

var NewWindow As new MainWindow
NewWindow.TextBox_1.Text = ReadData
NewWindow.TextBox_2.Text = ReadData
NewWindow.TextBox_3.Text = ReadData

NewWindow.Title="Note++ - "+FileDialog.Name
NewWindow.NameFile = FileDialog


end if

For Save As
var FolderDialog As FolderItem

if self.NameFile = nil then
FolderDialog = FolderItem.ShowSaveFileDialog(“text/plain”,“documenttxt”)

FolderDialog = FolderItem.ShowSaveFileDialog(“text/plain”,self.NameFile.Name)
end if

if FolderDialog <> nil then

var SaveFile As TextOutputStream
SaveFile = TextOutputStream.Create(FolderDialog)
SaveFile.Encoding = Encodings.UTF8



self.NameFile = FolderDialog

self.Title="Note++ - "+self.NameFile.Name

catch Error as IOException

end try

end if

Here is your problem:


ReadData = UserSelect.ReadAll()

var NewWindow As new MainWindow
NewWindow.TextBox_1.Text = ReadData
NewWindow.TextBox_2.Text = ReadData
NewWindow.TextBox_3.Text = ReadData



You write the data one by one. But on reading you read the same data into all 3 fields.

You need to do a bit of thinking here. How do you want to save your data? Are you going to extend your data? Where do you plan to take your app.

The easiest solution is to write a divider between the writes.


On reading you then do

NewWindow.TextBox_1.Text = ReadData.NthField(“field_divider”, 1)
NewWindow.TextBox_2.Text = ReadData.NthField(“field_divider”, 2)
NewWindow.TextBox_3.Text = ReadData.NthField(“field_divider”, 3)

The solution will work. But it will be brittle. The code depends on the textfields. When you add a text field you will have to change the code. If “field_divider” is in the text of your textfields the code won’t work.

1 Like

Is there any alternative as textfield contain field_divider.

That’s why I said that you need to think a bit. You could use json. You could use your own format like

TextBox_1:my text
TextBox_2:some text
TextBox_3:other text

json is easy to create and parse. For the second solution you can either use the text fields directly, which will be brittle again. Or you could use something called introspection which would automagically use the right textfield for the text. But this is a bit more technically advanced.

Thank You for the help. You really help me a lot.

There’s also the BinaryStream class, where you can save data serially:

Var bs as BinaryStream=BinaryStream.Create(MyFile)

bs.WritePString TextArea1.Text
bs.WritePString TextArea2.Text
bs.WritePString TextArea3.Text

It’s flexible and my preferred choice when writing to a file (with an extra command to save strings longer than 255 characters, unsupported by default).
This way isn’t suitable for files that the user should read, however.

Can you help me with redo text in text field.

What can be “redo” ?

i think undo
somehow ctrl z

My guess is that redo means UPDATE instead of INSERT.

redo is basically reverse of undo.