LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

variant data to anything

How do I convert variant data to different data types? Do I need to use always "variant to flattend string", read the data type and then implement the diffent types to cast them on the right way? Seems to bee little bit complicated. Is there a routine where this type cast is already implemented? I attached a small part of the vi to show you how it is implemented. I use datatypes cluster, strings and all types of numeric.
 
Best regards reto
0 Kudos
Message 1 of 5
(3,249 Views)
Hi reto
 
It seems as if you want to code some kind of generic property writer. There are several ways to do something like this. One way is what you are trying to do and there are others.
For instance you could write the flattened string directly to the file, you could define the type using lable prefixes instead of using the type descriptor to determine what type of value it is and there are others.
It depends on what exactly you want to do. If I want to store settings, I always create a cluster containing all the elements I want to store and use this cluster to write an xml-file. This works quite good for my purposes, maybe it won't for yours.
 
To answer your question - the only function to convert a variant to a specific data type is already used in your vi (variant to data). But there is no generic conversion function.
 
Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 2 of 5
(3,240 Views)
What  I will do is all the values from a global.vi  must be written to a config file. The globals values are saved in clusters. I will use the labels of the cluster as section and key. I use the references of the global vi so I need not to change the code when I  extend something in the globals. What I'm not understand is why this usefull typecast function variant to anything is not alredy implemented in labview. I have found some part of this function in the open g commander software.
 
reto  
0 Kudos
Message 3 of 5
(3,238 Views)
Exactly for this purpose I use xml-files. First I creat a strict type def control which main control is a cluster. This can be placed everywhere and just needs to be changed once. When writing the xml-file, I first create the xml-string using the Flatten to XML vi. The cluster can be wired to this vi directly and it works without any problems. The only thing you have to be aware of is, that the xml-file will be modified and previously written values will be lost. But I think this is a minor problem compared to the more readable code I get when using this method instead of casting types and writing config files.
 
Yes such a typecast function would not be bad, but I could manage to code whatever I wanted without such a function, although I already had some ideas, where I had used it. But in the end I found another way, that often was either simpler or more readable.
 
Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 4 of 5
(3,231 Views)
I'm using also xml files but in this case it's not possible. Thank's for your support.
0 Kudos
Message 5 of 5
(3,226 Views)