LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

dynamically creating a cluster

I have an array of strings which I read from a config file, and I want to be able to create a cluster of numbers for as many elements that are in the array, with the strings stored in the array as the element names for the cluster. Is there a way to do this, and if there is how would I go about inserting an element(actually an array of elements of corresponding sizes) into their corresponding locations in the cluster, and then how would I go about reading these elements back out of the cluster? Thanks.
0 Kudos
Message 1 of 3
(3,344 Views)
An equivalent in "C" of what you are really asking for is:

While my program is running, I want to add the statements to define a structure

typedef struct {
float number1;
float number2;
} newstruct;

newstruct Var1;

And use in my program variables typed to this structure:

Var1.number1 = 1.0;

It can't be done (neither in C nor G) since it requires that your program be recompiled to include the new structure and new datanames. Structures and datanames must be known at compile time. When you change/create a label (dataname) in LabVIEW, the VI must be recompiled (at least when this label is used).

Now you still have methods to handle dynamic data structures. First you could use the Config Files VIs. Open the config file, access the data b
y name (Read/Write Keys) Close the config file. There is no need to convert to another structure. Second to have a user interface to dynamic structure, you can take a look at some VIs I posted previously @ http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=137&HOID=50650000000500000025600000&HTHREAD=000024613&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0


LabVIEW, C'est LabVIEW

0 Kudos
Message 2 of 3
(3,344 Views)
> I have an array of strings which I read from a config file, and I want
> to be able to create a cluster of numbers for as many elements that
> are in the array, with the strings stored in the array as the element
> names for the cluster. Is there a way to do this, and if there is how
> would I go about inserting an element(actually an array of elements of
> corresponding sizes) into their corresponding locations in the
> cluster, and then how would I go about reading these elements back out
> of the cluster? Thanks.
>

As the other reply pointed out, you cannot do exactly what you asked,
but you can make a change to your datatype and things will work just fine.

Make the datatype be an array of clusters. Then inside of the cluster,
place a string and a
number. If I understand what you want, then you
can build some accessor VIs to look things up by name, to use instead of
unbundle by name, etc.

Greg McKaskle
0 Kudos
Message 3 of 3
(3,344 Views)