Search Values of Array in "One Go"

Bob Sneidar bobsneidar at
Thu Aug 24 16:13:01 EDT 2017

This will work with any array. It recursively calls itself as it encounters arrays within arrays. I agree with Richard that if all you want is one shot at an array to find the element(s) you are looking for, then this may (or may not) be a cleaner approach, but I think if you are taking multiple passes at finding/filtering with an array, this will at least get you there. If filtering with multiple passes, remember to put the text of the array in another variable  as filter *replaces* the contents of the source variable with the results. 

Here is the function. Thinking about it, I suppose you could modify this to include a filter parameter so that only the keys matching the filter would be returned. 

Bob S

function altPrintKeys @pArray, theKeyList
    put numtochar(11) into vertTab
    put numtochar(30) into altCr
    put the keys of pArray into theKeys
    sort theKeys numeric
    repeat FOR each line theKey in theKeys
        put "[" & theKey & "] " after theKeyList
        if theKey is not a number then
            replace "[" & theKey & "]" WITH "[" & quote & theKey & quote & "]" in theKeyList
        end if
        if pArray[theKey] is an array then
            put pArray[theKey] into theTempArray
            put altPrintKeys(theTempArray, theKeyList, pFullData) after theText
            put empty into the last word of theKeyList
            delete the last char of theKeyList
            put cr into the last char of theText
            put "pArray " & the last word of theKeyList into theKeyName
            -- put "put " & theKeyName & " into theValue" into theCommand
            -- do theCommand
            put value(theKeyName) into theValue
            replace tab WITH vertTab in theValue
            replace return WITH altCr in theValue
            put theKeyList & tab & theValue & comma after theText
            put empty into the last word of theKeyList
            delete the last char of theKeyList
        end if
    end repeat
    return theText
end altPrintKeys

> On Aug 24, 2017, at 12:14 , Sannyasin Brahmanathaswami via use-livecode <use-livecode at> wrote:
> what about a 2 diminsional array

More information about the Use-livecode mailing list