Textwriter not writing to file

rls456

Member
Licensed User
Longtime User
The following code does not save the data to file.

Sub ListView1_ItemClick (Position As Int, Value As Object)
Dim TextWriter2 As TextWriter

TextWriter2.Initialize(File.OpenOutput(File.DirInternal,Value & ".rls", True))
TextWriter2.WriteLine(EditItem.Text)
TextWriter2.Close
Panel1.Visible = False
ListView1.Clear
EditItem.Text = ""
Msgbox("Item successfully added.","Success")
End Sub
 

kickaha

Well-Known Member
Licensed User
Longtime User
It is probably worth checking that Value contains the string you are expecting it to have.

If you replace the line
B4X:
TextWriter2.Initialize(File.OpenOutput(File.DirInt ernal,Value & ".rls", True))
with
B4X:
TextWriter2.Initialize(File.OpenOutput(File.DirInternal,"test.rls", True))
does it save a file called test.rls?
 
Upvote 0

rls456

Member
Licensed User
Longtime User
How do you know that nothing has been added to the file ?
Are you shure that EditText.Text has text in it ?

Best regards.

Yes I read the file into a list and data added does not appear the original data is there but not the appended data.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Assuming that you get no error message, what happens if you hard code the filename. I have a feeling that the file name is not being picked up from the ListView.

If possible post up a small app tha demonstates the problem as it will be easier for us to find the issue.
 
Upvote 0

cammel8

Member
Licensed User
Longtime User
B4X:
TextWriter2.Initialize(File.OpenOutput(File.DirInt ernal,Value & ".rls", True))
I don't know if it is in the code like this or just in the post, but you have a space in internal. it should read:
B4X:
TextWriter2.Initialize(File.OpenOutput(File.DirInternal,Value & ".rls", True))
 
Upvote 0
Top