[posted and mailed]
craig.graham@lancaster.ac.uk (Craig Graham) wrote in
<8p2tgl$bu0$1@sponge.lancs.ac.uk>:
>
>Christopher Hodge wrote in message
>news:8p2sej$ncv$1@news3.bu.edu...
>
>> Specifically, I'd like to pass an arbitrary cluster into a for loop,
>> have it auto-index, and unbundle an element at each loop iteration. Is
>> anything like this remotely possible?
>
>Nothing simple. Certainly you can't pass an arbitrary cluster into a for
>loop and have it unbundle element by element as you suggest- how would
>the problem of multiple datatypes passing along the same wire inside the
>for loop possibly be handled?
>
>I've never tried doing it, and it'll be a pig, but check out the
>"Flatten to string" and "Unflatten from string" functions. With these
>you could conceivably write a function that indirectly takes an
>arbitrary datatype, including a complex cluster, processes it and
>returns a similar datatype. Whether the significant effort would be
>worthwhile is dubious.
>
I don't see how there is any advantage to this? Presumably the reason for
using a for loop is to allow similar processing of each element. In that
case I suspect that the cluster should therefore be composed of similar
elements. Processing clusters of "same" elements from cluster to and from
arrays are tools already built into LabVIEW.
Since you can already do this for clusters where all the elements are the
same then one way to do it for clusters with disimilar elements is to use
clusters that contain themselves two similar elements. As suggested above
one of these elements would be a "flattened to string cluster". Element 1
would be a NAME as a string and element 2 is a string representing the
FLATTENED CLUSTER.
To access the sub-elements in the FLATTENED CLUSTER, a case structure
within the for loop could handle the various unflattenings dependent on the
NAME of element 1. Simlarly because we are working with the same data types
(two stings) within our cluster, you can easily write VI's that will add,
remove or resize as needed using the tools already provided.
Another neat trick is to create templates and store these in your user.lib.
You could create a generic template that would allow you to re-use the
decoding VI's that give access to the sub-elements.
cheers, Alex
--
Alexander C. Le Dain, PhD
ICON Technologies Pty Ltd
http://www.icon-tech.com.au