LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing a cluster like a hashtable

Hi,
I have been trying to make a small scripiting language for a labview program that would allow the user to specify the value that he wants to assign to a value in a cluster. For example, say my cluster has a field named "q" and a field named "v". I want the user to be able to type q 10 and set the "q" field to 10. The problem is that I have not found any way to enter the cluster field name as a string, like I would be able to do in a hashtable in an ordinary programming language.
 
So then I tried making my own VI that converts the cluster to XML, does a search and replace to do what I want, then converts it back to a cluster. The problem is, it doesn't seem like there's any way to allow the VI to take in a generic cluster, only a cluster of a specific type. Then I tried creating a control from the cluster->XML  VI's "anything" terminal, but that didn't help either.
 
Does anyone have any ideas?
0 Kudos
Message 1 of 6
(3,989 Views)
If I understand what you need this may do what you want.  You could put it in a for loop to search for different field names.

Brian
0 Kudos
Message 2 of 6
(3,979 Views)

You can't access cluster elements by name, because clusters are always handled by their structure. There is no such thing as a "generic" cluster. Only an empty one.

What you can do is manage each element of the cluster seperately, but you have to know the structure of the cluster in advance.


___________________
Try to take over the world!
0 Kudos
Message 3 of 6
(3,977 Views)
Clusters dont seem very suitable for this.
 
I would suggest to keep two arrays, one for the values (numeric) and one for the tags (array of strings).
Now just parse your line, find the index of the tag in the string array, then replace the numeric array element at the same index.
 
Attached is a simple example (LabVIEW 7.1).
0 Kudos
Message 4 of 6
(3,971 Views)
In the properties of a cluster there is an array refnums ti the elements in it.  If you already know the name of the element you want to change you can search for that element's label name and make the changes there.  This will be slower than using the array method, but if you have existing code and are stuck with clusters this will work.




0 Kudos
Message 5 of 6
(3,963 Views)
In addition to all the other advice you are getting, one other thing I would recommend is that you modify your proposed script "syntax" to utilize post-fix notation. It's much easier to parse and the resulting language is extensible with a very linear degree of effort--unlike normal in-fix notation that get exponentially more difficult to parse the more complex the notation gets.
 
If this interests you I can send you a command processor that I wrote to allow users to define custom math operations that they wanted to run against their data.
 
Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 6 of 6
(3,960 Views)