returning result from a function when the number of items in the result varies
Stephen Barncard
stephenREVOLUTION2 at barncard.com
Sat Sep 20 20:45:01 EDT 2008
You've practically designed it!
Arrays are your friend.
{ below not tested}
function yourFunction arrayVar
put Timestamp & tab & "FDSFSDF" into myArray[garbage]
put "toad" into myArray[green]
return myArray
end yourFunction
put yourFunction() into Array
combine array with return and tab
put Array
-->
garbage<tab>20080923<tab>FDSFSDF
green<tab>toad
To get the number of elements in an array:
number of lines in myArray
even better ( I love this one - think binary):
repeat for each line tKey in the keys of tArray
put tArray[tKey] & return after tArrayContents
end repeat
to sort:
put the keys of myArray into myVariable
sort lines of myVariable
>I'm having trouble sorting this out. I have a function that searches through
>lines of tab delimited text. The number of lines varies from one to ten. The
>result from the search is two things. A data element and a pointer that says
>which kind of data element. Sometimes the result is one data element and one
>pointer and sometimes the result is another quantity like three data
>elements each with their identifier. To have this returned by the function
>it seems I need an array. I'm inexperienced at using arrays but I imagine
>that you just build it in the function and that is what is returned and then
>the identifiers for each data element are the keys and it makes no
>difference how many lines are in the array? Perhaps I also return a counter
>which says how many lines of data are in the array?
--
stephen barncard
s a n f r a n c i s c o
- - - - - - - - - - - -
More information about the use-livecode
mailing list