2D and Multidimensional Arrays in Revolution 1.8

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mokogobo
Posts: 37
Joined: Wed Jun 18, 2008 6:27 pm
Contact:

2D and Multidimensional Arrays in Revolution 1.8

Post by mokogobo » Thu Jul 24, 2008 6:34 am

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?

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm

Post by Bernard » Thu Jul 24, 2008 10:26 am

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.

mokogobo
Posts: 37
Joined: Wed Jun 18, 2008 6:27 pm
Contact:

Post by mokogobo » Thu Jul 24, 2008 1:49 pm

Bernard wrote: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.
Not confused but mistaken. I meant to say version Revolution 2.8. Are there multidimensional arrays in Revolution 2.8?

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Post by malte » Thu Jul 24, 2008 2:32 pm

No, there aren't

They will arrive with 3.0 (and are a joy to work with :-))

All the best,

Malte

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Thu Jul 24, 2008 3:11 pm

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:

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"]
Now you can loop through the array like this:

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

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm

Post by Bernard » Thu Jul 24, 2008 6:22 pm

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/)

mokogobo
Posts: 37
Joined: Wed Jun 18, 2008 6:27 pm
Contact:

Post by mokogobo » Thu Jul 24, 2008 7:24 pm

I like the comma trick. I'm curious how this works. The array's index/key doesn't appear to be a string or an integer when using the comma method you described. What exactly is the index/key in this case?

Thanks.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Thu Jul 24, 2008 7:30 pm

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"].
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

mokogobo
Posts: 37
Joined: Wed Jun 18, 2008 6:27 pm
Contact:

Post by mokogobo » Thu Jul 24, 2008 8:49 pm

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"].
Very cool. I appreciate your help. :-)

Post Reply