LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Variant to data conversion

I am using a property node to read an array element value using ArrElem.Value. I then want to convert the variant to data using the variant to data vi, but I get Error91 occurred at Variant to Data. I would appreciate any suggestions as to why this is occuring.
0 Kudos
Message 1 of 11
(3,890 Views)
If you connect an object of correct type to the type input of the 'variant to data' function no error should occur (at least it did not when I tried it: I used a 2D array of DBL and connected a DBL constant to the type input). So what exactly was your data type?

Besides that it seems to me that with the prop node 'ArrElem.Value' you get the value of the most recently edited element of the array. Is that what you want? It might be better to use the Value property to get the entire array and then to index the array element you want to read.
0 Kudos
Message 2 of 11
(3,892 Views)
The best way is to simply wire the index from array function and it is a lot clearer and faster also !
Remeber LabVIEW is a data flow language, only use property nodes when everything else fails !
greetings from the Netherlands
0 Kudos
Message 3 of 11
(3,892 Views)
Of course Albert's answer is perfectly right and I should have argued like him in the first place.

In my answer I just had uncritically implied that 'mhester' had had some good reason to use a property node, e.g. because he wanted to monitor changes of the array in a parallel running VI.

But even then other approaches like e.g. globals or the good old 'LV 2 style' globals would probably the better approach, since the 'property node' way to access the data of a control or indicator is the slowest and most inefficient.


Actually, I'd like to make Albert's statement even stronger: If you abandon the data flow paradigm at some point in the program you are quite likely to run into troubles at some later point in your program development.


Thanks for the clarification to Albert
0 Kudos
Message 4 of 11
(3,892 Views)
The array is read from the instrument I am controlling, and the user then selects an element in the array to send back to the instrument to tell it what to do. The array read in may change as will the element selected. What is the best way to do this? Please be specific; I am new to LabView. It is currently working using property nodes, but I would like to make it more efficient.
0 Kudos
Message 5 of 11
(3,892 Views)
Use the 'Index Array' function located in row 1 column 2 of the 'Array' pallette on the block diagram. Wire the array to the 'Array' input and the index value to the 'Index' input. (For arrays with higher dimension than 1 additional index inputs occur, but in your case you probably have a 1D array only).


As a beginner, keep your hands off the property nodes for a while, they are an advanced concept, and you can do 90 % of the tasks without them!


I can give more specific help if you post a code fragment demonstrating what you want to achieve...
0 Kudos
Message 6 of 11
(3,892 Views)
I have attached an example to show what I want to do. I put a constant array in the example, but the actual array is read from the instrument and can change. It is always 1D, though. The user selects an element in the array, and I get the index. Thanks for the help.
0 Kudos
Message 7 of 11
(3,892 Views)
Please post it as LV 7.0 (Menu 'File'-->'Save with Options'-->'Save for Previous'), I don't have version 7.1 and can't open the VI
0 Kudos
Message 8 of 11
(3,892 Views)
0 Kudos
Message 9 of 11
(3,892 Views)
OK, I think I understood now what you're trying to do, and you can indeed do it that way. But there might be better ways...

E.g., does the user of your VI know the values in the array beforehand? Or does he have to browse through the array to find the element he wants? That would seem a bad approach to me, since he has to select a lot of unwanted values and you have to program an extra OK button to let the user input his final choice.

If the size of the array is not too big, why not present the data as a listbox, where the user can select the value. I attach a VI demonstrating it.
0 Kudos
Message 10 of 11
(3,892 Views)