Arrays - accessing & indexing numerically

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Iluvatar
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 8
Joined: Fri Apr 09, 2010 8:59 am

Arrays - accessing & indexing numerically

Post by Iluvatar » Sat Jan 19, 2013 6:22 am

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 :?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Arrays - accessing & indexing numerically

Post by Simon » Sat Jan 19, 2013 6:58 am

Can you:
set the numberFormat to "###"
When creating the array?
That will give you 001 002 003 etc.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Arrays - accessing & indexing numerically

Post by jacque » Sat Jan 19, 2013 10:02 am

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply