Adding a Large Quantity of Values to an Array - Help

Hello,

In my application, I am using several arrays to handle a long list of items. About 100-200 or so per array. Maximum may end up around 500.

I’m using a 1-dimensional array for each. Strings, not numbers. Also, I’m using 2018R3.

What is the best way to load a long list of values to an array? Initially, I put them in an external file and read them in. This works fine, but as the contents do not change, I’d rather build them into the application itself rather than rely on external files that may get lost or accidentally deleted.

Setting up an array like this:
names = Array(“Leonard”, “Abraham”, “Herbert”)
works fine for short lists, but is rather cumbersome for long lists.

To make it a little easier, I defined a text value as:
namesToLoad=“Leonard,Abraham,Herbert,[…dozens more…],Frank”
Then load that into an array by using the commas to split the values.

That works but still a long list is rather cumbersome. Xojo keeps everything on a single line and there does not appear to be a setting to allow it to wrap lines within the view window. So, I end up with long lists that are slow to scroll left and right to add additional values.

Something like names.AddMultiple(“John”, “Joe”, “Bill”) would be handy as then I could break it up across multiple lines. But that’s unfortunately not an option.

Only thing I’ve found is to take the selected area of code, copy it, paste it into TextEdit, work on it there, then bring it back into Xojo. It would be easier if I could just do everything in Xojo itself.

Any suggestions?

Thanks!

sqlite for data and sqlite in memorydb for access?

If setting as an external file works but you just don’t want the external file you could set the contents of that external file as a constant in your app. This would write the contents of the file into your app binary, but you wouldn’t have the chance of losing the file.

In a constant, put each value on its own line, then split by EndOfLine.

1 Like