Page 1 of 1

2D and Multidimensional Arrays in Revolution 1.8

Posted: Thu Jul 24, 2008 6:34 am
by mokogobo
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?

Posted: Thu Jul 24, 2008 10:26 am
by Bernard
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.

Posted: Thu Jul 24, 2008 1:49 pm
by mokogobo
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?

Posted: Thu Jul 24, 2008 2:32 pm
by malte
No, there aren't

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

All the best,

Malte

Posted: Thu Jul 24, 2008 3:11 pm
by trevordevore
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

Posted: Thu Jul 24, 2008 6:22 pm
by Bernard
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/)

Posted: Thu Jul 24, 2008 7:24 pm
by mokogobo
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.

Posted: Thu Jul 24, 2008 7:30 pm
by trevordevore
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"].

Posted: Thu Jul 24, 2008 8:49 pm
by mokogobo
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. :-)