Anyone have a recommendation for the best way to add some arbitrary data that can be accessed in a lookup table format?
For instance, I have a table of 1000 UInt8 values that were generated by another source outside of my Xojo project. These values can’t be generated or re-created by an equation. I need to have this data in my Xojo project so I can “lookup” a value given an index into the “array”.
The only way I figure I can do this is to put the 1000 bytes into a binary file, then load them with BinaryStream into a MemoryBlock, then use the MemoryBlock accessors to retrieve the values.
I’d really prefer not to have this data in a file that must be loaded separately. Is there some way to make a 1000-byte “string constant” that contains raw (non-printing) data?
It sounds like you’re wanting an array available in the app when it launches. You could make a tab or comma delimited string and add it as a constant, then on launch just split it into an array. Or you could create an XMLDocument and add that as a constant and load it on launch.
You can always put this in as a string constant and when the app starts up and does initialization read the constant and split it up into an array or dictionary. That’s for small amounts of data.
For larger amounts of data I would actually put a database (sqlite) into the resources directory and just read it. If you use encryption no one but your app will be able to read it.
A massively low-tech solution:
Have a listbox on some window, and put the 1000 rows into the listbox as the initial value at design time.
Then you can refer to the list by index : window1.listbox1.list(x)
Its less useful than a dictionary which can be searched quickly.
JSONItem.Load() from a file.
JSONItem.Value() to assign or lookup associated values with a key value.
JSONItem.ToString() to save it back to a file, if needed.
[quote=157785:@Jeff Tullin]A massively low-tech solution:
Have a listbox on some window, and put the 1000 rows into the listbox as the initial value at design time.
Then you can refer to the list by index : window1.listbox1.list(x)
Its less useful than a dictionary which can be searched quickly.[/quote]
If you are going that route, why not an Array… less overhead than a window and a listbox
in a Module
dim v() as string
in App.Open
v=split(mydata,endofline) // where mydata is a 1000 line file that was dragged into the IDE
If you drag a file into your project, it becomes a string constant. And it can contain binary data. So write the values into a file and drag it in. Split it into an array or dictionary or whatever and you’re good to go.
In my case, the answer turns out to be a variant of what Tim Hare suggested. I created a binary data file and simply dropped the file into the project hierarchy and gave it a name, let’s call it “LookupTable”.
Then, in the project, I can refer to the data by name and use the MemoryBlock functions on it. For instance, if I need to fetch a byte from this data block (let’s say with an byte offset of 739), I do this: