2D and Multidimensional Arrays in Revolution 1.8
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
2D and Multidimensional Arrays in Revolution 1.8
Does the latest version of RunRev 1.8 support multidimensional arrays? I'm wrapping up some database code into nicer routines, and multidimensional arrays would be perfect for what I'm doing.
What I'd like to do is be able to access the results of a query in an 2D array like "results[row][column] = column's value for the row" where I'd substitute row for a row number and column with a column name (e.g., results[3]["id"]).
I can extract and prepare everything fine, but I'm unsure how I would go about using a multidimensional array in RunRev. I've considered assigning the columns to items and rows to lines, but I would like to use the column names rather than the column numbers.
Any ideas?
What I'd like to do is be able to access the results of a query in an 2D array like "results[row][column] = column's value for the row" where I'd substitute row for a row number and column with a column name (e.g., results[3]["id"]).
I can extract and prepare everything fine, but I'm unsure how I would go about using a multidimensional array in RunRev. I've considered assigning the columns to items and rows to lines, but I would like to use the column names rather than the column numbers.
Any ideas?
Strictly speaking, it is in the next version of Rev (currently in beta) that true multidemensional arrays are coming (the last Rev newsletter had an article on that). You could sign up for the beta program, and then you'd have access to these straight away. As for the version 1.8 you refer to, I believe you are confused. The current version of Rev is 2.9. I've been using Rev since 1.1.1 and there was never a 1.8.
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
If you need to use 2.x in your current project then I would suggest using commas to mimick a multi-dimensional array. For db records this works pretty well. Pseudo code:
Now you can loop through the array like this:
Code: Select all
put 0 into i
repeat through cursor
add 1 to i
put cursor column into theArray[i, column]
end repeat
put i into theArray["count"]
Code: Select all
repeat with i = 1 to theArray["count"]
put theArray[i, COLUMN]
end repeat
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
I considered recommending that too Trevor, as that is what you use in libdatabase (libDatabase is a great way of working with databases from inside Rev: http://www.bluemangolearning.com/developer/revolution/)
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Looks can be deceiving 
The key is still a string. If you check the keys of the array you will see something like "1,COLUMN".
The way Rev works you can write theArray[1, "COLUMN_NAME"] and everything works as intended in the end and I find it easier to read. Of course in 3.0 this is no longer necessary as you can write theArray[1]["COLUMN_NAME"].

The key is still a string. If you check the keys of the array you will see something like "1,COLUMN".
The way Rev works you can write theArray[1, "COLUMN_NAME"] and everything works as intended in the end and I find it easier to read. Of course in 3.0 this is no longer necessary as you can write theArray[1]["COLUMN_NAME"].
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Very cool. I appreciate your help.trevordevore wrote:Looks can be deceiving
The key is still a string. If you check the keys of the array you will see something like "1,COLUMN".
The way Rev works you can write theArray[1, "COLUMN_NAME"] and everything works as intended in the end and I find it easier to read. Of course in 3.0 this is no longer necessary as you can write theArray[1]["COLUMN_NAME"].
