Page 1 of 1
combine a multidimensional array [SOLVED]
Posted: Thu Apr 17, 2014 4:22 pm
by atout66
Hi to all,
I've a problem when I want to combine an array as myArray[][]. I extract the array which is stored into a custom propertie of a field into an other var like explained in the LC's lesson.
http://lessons.runrev.com/s/lessons/m/4 ... able-field
Here is my code with comment:
Code: Select all
-- From <leMot> we extract the custom propertie which is an array
put the leMot of fld laCard of stack laStack into tArray -- OK until here
combine tArray using return -- destroy tArray !!!
set the unicodeText of fld leFld to uniEncode (tArray, "UTF8") -- empty
Any idea would be much appreciated
Kind regards, Jean-Paul.
Re: combine a multidimensional array
Posted: Thu Apr 17, 2014 5:45 pm
by Thierry
atout66 wrote:
I've a problem when I want to combine an array as myArray[][].
AFAIK, split and combine doesn't work with multidimensional arrays.
You have to roll your own...
Regards,
Thierry
Re: combine a multidimensional array
Posted: Thu Apr 17, 2014 6:38 pm
by magice
You need to use a repeat loop to combine the first dimension, than you can combine the second. This works well if the keys are numbers. One thing to be aware of though, is that if the second dimension contains more than 9 elements, the process can corrupt the order. This is because a computer will put 10 after 1 and before 2. Just keep that in mind when you split the array later.
Code: Select all
repeat with i= 1 to tCounter --A variable i keep for the number of sets of data
do "combine tArray["&i&"] using comma"
end repeat
combine tArray using cr
Re: combine a multidimensional array
Posted: Thu Apr 17, 2014 7:53 pm
by atout66
Thanks to all
You're right, I must use a loop. That's what I did like:
Code: Select all
get the keys of tArray -- = dim()
repeat with aa = 1 to the number of lines of IT -- read each element of the second column
put tArray[1][aa] into laValeur
set the unicodeText of fld leFld to uniEncode (laValeur, "UTF8")
wait 3 second -- to see
end repeat
I'll look farther how to get a loop with the first column, here [1].
Kind regards, Jean-Paul.
Re: combine a multidimensional array [SOLVED]
Posted: Thu Apr 17, 2014 9:19 pm
by rkriesel
atout66 wrote:Any idea would be much appreciated
Hi, Jean-Paul. As you've seen, combining a two-dimensional array is fairly simple. Do you want to combine an n-dimensional array, as your subject line suggests?
-- Dick
Re: combine a multidimensional array
Posted: Fri Apr 18, 2014 9:47 am
by atout66
Hi Dick,
Yes, that's what I'm looking for.
Currently, I can read only one element of the first row, column after column.
But what if I have this kind of array ?
[1][1] , [1][2] , [1][3] , [1][4]
[2][1]
[3][1] , [3][2]
[4][1] , [4][2] , [4][3]
My script work for [1][1] , [1][2] , [1][3] , [1][4] ; OK
But how can I guess that there is no [2][2] in that array ?
And how can I be sure that I must loop 4 columns in each row to be sure not to miss [1][4] value ?
Not simple at all for my current skill. With my old TBK (Toolbook) I could do that, but I'm discovering LC and it takes time and effort
Kind regards, Jean-Paul.
Re: combine a multidimensional array [SOLVED]
Posted: Fri Apr 18, 2014 10:34 am
by rkriesel
atout66 wrote:But what if I have this kind of array ?
[1][1] , [1][2] , [1][3] , [1][4]
[2][1]
[3][1] , [3][2]
[4][1] , [4][2] , [4][3]
Since your array has only two dimensions, you can combine it like this:
Code: Select all
repeat for each key tKey1 in tArray
repeat for each key tKey2 in tArray[ tKey1 ]
put tKey1, tKey2, tArray[ tKey1 ][ tKey2 ] & cr after tString
end repeat
end repeat
To reconstitute your array, you can split the string like this:
Code: Select all
repeat for each line tLine in tString
put item 3 of tLine into tArray[ item 1 of tLine ][ item 2 of tLine ]
end repeat
Note that the correctness of the code above depends on there being no comma or cr in your array.
Does that help?
-- Dick
Re: combine a multidimensional array
Posted: Fri Apr 18, 2014 10:56 am
by atout66
Hi Dick,
Does that help?
It could be
I've to look in deep at your code, specialy your first loop. I'm not used with the <for each> repeat.
Thanks for your help.
Kind regards, Jean-Paul.
Re: combine a multidimensional array
Posted: Fri Apr 18, 2014 2:08 pm
by atout66
Ah ! I've got it Dick
Step by step inside the debugger, I understood your loop in the loop. Very handy, thanks a lot for your help.
Kind regards, Jean-Paul.