How can I save notes?

BrutalSnyper

Member
Licensed User
Longtime User
In my note taking application, I would like to save the note that a user inputs to an editText box.
However, I'm not sure how I can save them so that they may be read later on.
I want the text in the box to be saved to either 1 .txt file, but so that it can be distinguished from other saves or have multiple text files but then be able to make the app know what number to add to the end?


Basically, I want to save multiple strings and then be able to read them back.
Help please :)
 

BrutalSnyper

Member
Licensed User
Longtime User
I read that already thank you, I just need help with the logic of saving multiple parts of text and whether to save them to multiple files or a single file.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
You will have to create a "save" button for example and request a file name to save it, if you want to add text to an existing note then load the file and put the content on an EditText, you will also have a list of all your created notes.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Consider using a database, you can then easily add fields to each record if you want to change the app. i.e. you can add a timestamp or tags etc
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
For learning purposes, I would advise you to try the files method, so you get used to B4A and file manipulation, but for effectiveness I agree with stevel05, a SQL will be much better.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Here is a small example:
Dim MyWriter As TextWriter
MyWriter.Initialize(File.OpenOutput(File.DirRootExternal, "DailyNotes.txt", True)) 'True means for append
MyWriter.WriteLine("I am a B4A rookie")
MyWriter.WriteLine("I am no NJDude.")
MyWriter.WriteLine(Label2.Text) 'you can also add edit text or label content
MyWriter.Close

Mahares
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If you want to add a date and time stamp as Steve suggested, here is below the code that works:
B4X:
Dim MyWriter As TextWriter
Dim DTstamp As String
DTstamp = "  " & DateTime.Date(DateTime.Now) & "  " & DateTime.Time(DateTime.Now)
MyWriter.Initialize(File.OpenOutput(File.DirRootExternal, "DailyNotes.txt", True)) 'True means for append
MyWriter.WriteLine("I am a B4A rookie" &  DTstamp )
MyWriter.WriteLine("I am no NJDude." & DTstamp)
MyWriter.WriteLine(Label2.Text & DTstamp ) 'you can also add edit text or label content
MyWriter.Close
 
Upvote 0
Top