Collapse (?) An Array?

Bob Sneidar bobs at twft.com
Thu Sep 1 12:53:49 EDT 2011


No Scott you are missing a bit of information here. Try this:
on mouseUp
   put "This is a test" into theArray[1]
   put "This is a second test" into theArray[2]
   put "This is a third test" into theArray[3]
   delete variable theArray[2]
   put the keys of theArray
end mouseUp

What you will get is:
1
3

There is no "empty slot. Now try this:
on mouseUp
   put theBogusArray[1]
end mouseUp

You will get empty. Referencing a nonexistent element of a nonexistant array returns empty. It does not generate an error. This is what is tripping you up. 

Bob


On Sep 1, 2011, at 7:10 AM, Scott Rossi wrote:

> Recently, Richard Gaskin wrote:
> 
>> The delete is fine; the problem is in the display of the results.
>> 
>> If you use:
>> 
>>   put theArray[1] &"*"&theArray[2] &"*"& theArray[3]
>> 
>> ...you'll get the empty entry for theArray[2].  The variable theArray
>> still exists, but there's nothing in that slot.
> 
> Yes, this is the problem.  I'm storing data in array form in custom
> properties, and my problem is after a delete, the remaining elements of the
> array are not reordered.
> 
> 
>> Building the output from the keys of the array will get what you want:
>> 
>>   put the keys of theArray into tKeys
>>   sort lines of tKeys -- if the order is important
>>   repeat for each line tKey in tKeys
>>      put "*"& theArray[tKey] after tResult
>>   end repeat
>>   put tResult
> 
> From what you're saying, it sounds like I need to put the remaining elements
> of the array into a temporary variable and then replace the original array.
> 
> Regards,
> 
> Scott Rossi
> Creative Director
> Tactile Media, UX Design
> 
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the Use-livecode mailing list