Page 1 of 1

Arrays - accessing & indexing numerically

Posted: Sat Jan 19, 2013 6:22 am
by Iluvatar
I have been reading widely about this but, as yet, have been unable to identify a solution. I have referred to all documentation I can find, including the User Guide, Dictionary, lessons, tutorials etc.

My question is:

If a have two sets of data which are related by a key (index) which has a numerical value and sequence (say, in time), how do I preserve that sequence? My example is as follows:

Data Set 1 - 1 2 3 4 5 6 7 8 9 10 11 12 13 .....
Data Set 2 - 0.6 0.6 0.2 0.45 0.45 0.88 0.66 0.99.....
(Note - the space separators do not denote a specific data type).

I need to be able to access and process these items together in their sequential order, not in the "hash" (string) order that they are stored by LiveCode. In effect, Data Set 1 is the numerical index for Data Set 2.

I realise that 'time' referred to above could be represented by a string 'timestamp', but that is not the question.

If I store Data Set 2 into an array, and I want to read them out in numerical index order of Data Set 1 (eg. DataSet[1] DataSet[2] .... etc) I cannot seem to do this. LiveCode thinks I want the string index; namely DataSet2[1] DataSet2[10] DataSet2[11] DataSet2[12] ... DataSet2[2].. etc

Can anyone help me with this ? I am confused :?

Re: Arrays - accessing & indexing numerically

Posted: Sat Jan 19, 2013 6:58 am
by Simon
Can you:
set the numberFormat to "###"
When creating the array?
That will give you 001 002 003 etc.

Simon

Re: Arrays - accessing & indexing numerically

Posted: Sat Jan 19, 2013 10:02 am
by jacque
Do you mean something like this?

Code: Select all

repeat with x = 1 to the number of words in dataset1
  put word x of dataset2 into myArray[word x of dataset1]
end repeat 
The keys will be the index numbers. You can sort them if you need them in order.