XOJO Notes Example

While I was checking the Xojo Notes Example I noticed it was doubling the amount of notes created every time you went to the ListView.
What could be causing that?

I should mention I created a new view with just a button on it that Pushed to the ListView

I’m guessing that since Note.LoadData is in the Open event, it just keeps appending the the saved data each time we revisit the view.

What’s the best approach to plug this bug?

Dim file As FolderItem
file = Xojo.IO.SpecialFolder.Documents.Child(“Notes.json”)
If file Is Nil Or Not file.Exists Then Return

Dim inp As TextInputStream = TextInputStream.Open(file, TextEncoding.UTF8)
If inp Is Nil Then Return

Dim inputText As Text = inp.ReadAll

Dim json() As Auto
json = Xojo.Data.ParseJSON(inputText)

For Each j As Dictionary In json
Dim n As New Note
n.Title = j.Value(“Title”)
n.Details = j.Value(“Details”)
n.IconNum = j.Value(“Icon”)
n.Category = j.Value(“Category”)



I would use a static boolean in Open to run the code only once.

[code]Static Already as Boolean

If not Already then
Already = True
// Do whatever you need to do

end if

My experience with Dictionaries is very limited so still playing with the example code.

What would a ClearAll Records Method look like?

If you want to clear all content just do

myDictionary = New Dictionary

all keys and values will be gone.

Hum. Xojo.Core.Dictionary for iOS does not have clear.

But it does have RemoveAll.

Thanks for the 2 suggestions but I still can’t integrate either of them. Can you tell me where they fit in the Xojo Notes Example (I think r2 and r2.1 are the same). Thanks Martin

You mean, to remove keys ?

To delete all the records in the Dictionary.

Post your code.

In order for it to be legible, please make sure to click on the code icon on top of the editor before you paste. Or select the code you pasted and click the code icon.

I tried iOS XojoNotes, but I’m not seeing this behavior at al. If you want to ensure that the Note.LoadData method does not duplicate the Notes array on multiple calls, then one thing you can do is to re-initialize the array at the beginning so new data does not get appended to any existing data. So at the top of LoadNotes, just do:

ReDim Notes(-1)

I am rusty, thanks Paul :slight_smile: