LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array to cluster with adjustable cluster size

You make a good point, tst.  Maybe this reply will bump the thread up and get some attention from someone at NI?

I was kinda surprised myself that it worked.  It even behaved sensibly when the input array was of the wrong size.

Input array size < typedef cluster size (including empty array) --> existing array elements mapped to cluster elements, remaining cluster elements set to default values*.

Input array size > typedef cluster size --> first N elements mapped, extra elements ignored.

*default values: I am not sure whether it used the default for the internal boolean datatype (False), or whether it used the default value from the cluster typedef (also all False in my app).  Because of my settings, I didn't exercise this aspect of behavior).

I also verified that the values of the cluster elements used as the "Type" input were ignored -- only their datatype was used.

Anyway, it sure seems like intentional conversion behavior, but perhaps undocumented and un-guaranteed.  That is kinda shaky, though I'll probably stick with it for this app which will ultimately be deployed as an executable.

-Kevin P.

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 11 of 27
(6,137 Views)
Hi all,

Let me explain my situation that I'm facing.. Currently I have created 42 elements of cluster of strings. And these strings are visible only to the user according to table's fields. For example, if the selected table have 5 fields it will only display 5 elements from the cluster and the rest will be invisible / hidden. Then I need to insert these 5 fields into the MS Access Database. The problem is, when I wire the cluster (which contains 42 elements) into the DB Tools Insert Data.vi, it will give me error saying that  "the number of columns does not equal the number of parameters". So I chose to use the Array to Cluster function but the cluster size is not adjustable.

Can someone pls help me on this? I just need to insert data into database according to the number of fields from the user select table. THANKS!!!!!
Message 12 of 27
(6,128 Views)
What is the input type of the DB Tools Insert Data.vi? Is that a variant to accept clusters of any size?
If that is a cluster of strings, the method proposed bt Kevin won't work since you can't typecast variable length data. However if the input of
DB Tools Insert Data.vi is a variant, there is a tool in OpenG Tools to convert an array to variant containing a cluster of the same size that you could wire to the input of DB Tools Insert Data.vi.


LabVIEW, C'est LabVIEW

0 Kudos
Message 13 of 27
(6,123 Views)
Hi Jean

Mine is a cluster of strings.. Pls refer to jpg file..

Thanks....
0 Kudos
Message 14 of 27
(6,114 Views)
Hi... Aitortxo

I've tried the method that you had suggested here but didn't work (up to my understanding). Could you pls create an example of yours and let me take a look? As when I tried to wire the second Array to Functions in a Case Structure with different size (let's say the first one is 1 and the second is 2) the wire was broken.

Thanks....
0 Kudos
Message 15 of 27
(6,115 Views)

The wire would be broken because LV is strictly typed - once a wire has a certain data type (e.g. the 1 element cluster) you can't connect another type into the same wire. As was originially suggested, you need to convert it to a variant.

The Insert Data VI uses a variant as an input with a parser inside it to convert to DB data types. To accept more than one element it parses the input cluster or array. This means that If you only have strings you can build an array out of them and wire that array into the Insert Data VI or use JP's method.

What I would suggest, however, is to work in a different way. Normally, when working with DBs, the DB should be designed to fit the data. The user should not update records in the DB but work on the data. That is, you would have a single VI which would accept input X and perform task Y. This usually makes programs more portable and readable but requires some more work to implement, especially in your case.


___________________
Try to take over the world!
0 Kudos
Message 16 of 27
(6,115 Views)
Thanks tst for the response... but I still couldn't find a way to solve my problem...... Smiley Indifferent
0 Kudos
Message 17 of 27
(6,105 Views)

Wait a minute... I think I understand the problem better now.

You have a single cluster to account for all the tables in your DB? That's really unnecessary.
Even without changing your DB design to reflect the data structure instead of the UI you could still use more than one cluster. For example, create a VI which will update table X. The VI will have a UI cluster of the appropiate size and will also know which names to call. You need to create such VIs (or tab pages or any other similar device) for every table in your DB and then you won't have to bother with hiding and selecting elements and so on - just open the VI which updates the table you need.

If this doesn't help you, you should post your actual code, preferably only the part of it which deals in this cluster\array and in 7 or 7.1 format.

BTW, why can't you just extract the selected elements from your array (example attached) and wire that array into the Insert Data VI?


___________________
Try to take over the world!
0 Kudos
Message 18 of 27
(6,095 Views)
Hi 222:

The "DB Tools Insert Data" function works in two ways. One if Data input is a cluster, and another if Data input is not a cluster.

You try to use it in the first way. Why not try the second?

If you have an array with correct number of elements and you have another array with table's corresponding column names, you can insert data with a For Loop. Data input would be indexed from the first array and column input would be indexed from the second array.

This can be a SubVI with 4 inputs (DB Ref, 1st Array, 2nd Array and Error in) and 2 outputs (DB ref and Error out), and you can name it Save to DB

Hope it helps,
Aitortxo.
0 Kudos
Message 19 of 27
(6,089 Views)

Have you considered inserting into your database using a sql command instead of a cluster.  Parsing a sql command is very easy to modify since it is a simple string.  Building a complex string is much easier (in my opinion) and flexable than trying to handle clusters or variants.

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 20 of 27
(6,081 Views)