To File.WriteString or Not to File.WriteString that is the question

Shane119

Member
Licensed User
Longtime User
Hi Everyone

Just started with using the Files and got a perculiar error.

I have a list of sayings in the file "Sayings.txt" in the File.DirAssets - I read this into a EditView ok - no problems with the File.ReadString.

I then try and write it back to the same file and I get the following error message:

"An error has occurred........AssetsDir/Sayings.txt (No such file or directory)..

How can this be when I've just read from it?

The following is my code, thanks in advance for any help

Shane


Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("EditSayings.bal")
If firsttime Then
txtSayings.text = File.ReadString(File.DirAssets,"Sayings.txt")
state.TheSayingsTxt = txtSayings.Text
End If
End Sub

Sub Activity_Resume
txtSayings.text = State.TheSayingsTxt
End Sub

Sub Activity_Pause (UserClosed As Boolean)
SaveState
If userclosed = True Then
activity.Finish
End If
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean ' Return true to consume the event
If KeyCode = 4 Then ' Back button
' -- do something here --
If Msgbox2("Are you sure want to close without saving?", "Save Sayings", "Yes", "", "No", Null) = DialogResponse.POSITIVE Then
Return False
Else
Return True
End If
Else
Return False ' Do not consume, the app will close or go to previous activity
End If
End Sub


Sub SaveState
State.TheSayingsTxt = txtSayings.text

End Sub

Sub btnSave_Click
File.WriteString (File.DirAssets,"Sayings.txt",txtSayings.Text)
activity.Finish
End Sub
 
Top