I have a multidimensional array that I created from a spreadsheet. So several rows and columns. The first column (sequential numbers) becomes the key. So I can say e.g.
and get Paris. I have been scratching my head for a long time. How can I transform my array? I have tried to reset the key, but to no avail. Any education welcome!
repeat for each key tCountryNumber in Countries
put Countries [tCountryNumber] into taCountryInformation
put taCountryInformation["Country"] into tCountry
put taCountryInformation["Capital"] into tCapital
put tCapital into taCountries[tCountry]["Capital"]
end repeat
The array taCountries should have the array you want.
It can be done in less code but this way I hope you see what is happening.
Did not test any of this so a mistake could be involved.
kaveh1000 wrote: Sat Jan 04, 2020 11:50 pmHow can I transform my array?
you can't! You have to "re-create" the array, but the best method is of course, as Paul pointed out,
to create the array directly with the desired keys (key names).
kaveh1000 wrote: Tue Jan 07, 2020 8:54 pm
No, I can use custom properties of buttons. I find that quite intuitive. I thought arrays might be faster, though not much data.
I would often use tables with tabs and just access each column as needed. But my data has lots of returns in each element so hard to use tables.
If the problem lends itself to rows and columns, I'd probably just leave the data in rows and columns.
For large data sets accessed frequently, there can be some good advantages to using arrays. But the best use of arrays is when they fit the problem at hand.
Richard Gaskin LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
but this could be a big hassle if your data contains returns. Therefore I would recommend SQlite.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Thanks Mark. Actually I don't have to do any clever filtering. And I want the data entry to be kept very simple. So I am keeping the data in Google Sheets, and reading them when LiveCode opens a stack. Then I just keep in memory. I actually successfully used MySQL, but I migrated to Google Sheets in order to simplify data manipulation.
Okay, but then you can't do what you want to do according to your original question. All fine by me.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
I import the data into an array, but the keys are automatically the row numbers. Using Paul's suggestion I change set the keys to a name. So that works.
But I am now thinking of creating buttons and setting all the data as custom values. so the button names are the keys. This works for me as I need the buttons anyway, in order to select which "rows" I want to take action with. So I will use the Google Sheet as a "style sheet" to create buttons on the fly and populate each with the values. Then no trouble with data with line breaks.
sorry it is not clear but I find custom values very intuitive and in my case it works as I need buttons.
dunbarx wrote: Tue Jan 07, 2020 8:26 pm
A couple of posts recently involving array issues when keys are numbers. This usually because it is left up to livecode to supply them.
This is similar to numbering your field names. Don’t
It depends on the situation. Usually I name array keys but in my current project I need numbers. The array represents pages in a book and I need to access the page content non-sequentially. Splitting the array without a secondary delimiter gives me an array with page numbers as the keys.
So, it depends.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com