Easy quick hypertalk coding question

Eric Chatonet eric.chatonet at sosmartsoftware.com
Mon Apr 14 13:13:45 EDT 2008

Bonjour William,

Le 14 avr. 08 à 18:39, william humphrey a écrit :
> I forgot to say that it is a converted hypercard stack with  
> thousands of
> cards. When in Hypercard I accomplished this by sorting the stack  
> by the
> index fld.
> On Mon, Apr 14, 2008 at 9:40 AM, william humphrey  
> <shoreagent at gmail.com>
> wrote:
>> Can someone help me with a function?
>> If sort all cards by fld "index" doesn't work and fld "index" has  
>> a bunch
>> of numbers in it which aren't in order and skip some values how do I
>> 1. Find out what is the highest value in fld "index"?
>> 2. Find out a list of any numbers that are duplicates?
>> I'm afraid that I do to much work of this sort in Excel and I  
>> can't think
>> of a way to do this without dumping all the values to memory and  
>> working on
>> them there.

The precision about the number of cards is important.
You say that your fld "Index" may have several values in it or I  
missed something?
If all this is right, you could first run a code snippet to set a  
custom property of every card to the higher value in its index:
Custom properties are not supported by HyperTalk but appear very  
useful in Revolution ;-)
See the user guide.

function HigherValue pCdNumber
   local temp
   put fld "Index" of cd pCdNumber into temp -- I assume several lines
   replace cr with comma in temp
   return max(temp)
end HigherValue

To set all cds in the stack:

repeat with i = 1 to the number of  cards
   set the uIndex of cd i to HigherValue(i) --
end repeat

You can run this code at any moment :-)
And you have now a custom property named uIndex that keeps the max  
value of each index field
Then you can 'sort cards [direction] [sortType] by the uIndex of this  

About to find duplicates, assuming you want to search the custom  
property set above:

function DuplicatedCards
   local tIndexList ,tDuplicates
   repeat with i = 1 to the number of  cards
     put the uIndex of this cd & cr after tIndexList
     if the uIndex of cd i is among the lines of tIndexList then
       put the short name of this cd & cr after tDuplicates
   end repeat
   delete char -1 of tDuplicates
   return tDuplicates
end DuplicatedCards

Not sure if all this helps but if you are more specific many people  
on this list will be able to help you :-)

Best regards from Paris,
Eric Chatonet.
Plugins and tutorials for Revolution: http://www.sosmartsoftware.com/
Email: eric.chatonet at sosmartsoftware.com/

More information about the Use-livecode mailing list