LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SubVi with input as either string og number

Solved!
Go to solution

Got this small subvi. I wonder if I could make it more flexible and let it be able to take both string and number as a value input (market as "value dbl").  Is there a kind of variant variable which could be used?

Capture.PNG

0 Kudos
Message 1 of 7
(3,402 Views)

You cannot use variant when writing to Configuration file. But you can create polymorphic VI, so that be able to wire either numeric or string to the subVI input.

 

Thanks,

Arev

 

CTO | RAFA Solutions

 

Certified-LabVIEW-Embedded-Systems-Developer_rgb.jpgCertified-LabVIEW-Architect_rgb.jpg

0 Kudos
Message 2 of 7
(3,382 Views)
Solution
Accepted by topic author Michael.Koppelgaard

Michael.Koppelgaard a écrit :

Got this small subvi. I wonder if I could make it more flexible and let it be able to take both string and number as a value input (market as "value dbl").  Is there a kind of variant variable which could be used?

 


It is possible with the OpenG Write Key (Variant)_ogtk.vi. But the issue is that when you want to read it back you have to know what type it was. If you write to different section of the config file each with a specific type the it will work. With this solution you need to use the OpenG Read Key (Variant)_ogtk.vi to read and convert the value back into LV.

 

Another way is to use Get Type Information.vi from the Data Type Variant palette. The trick here is to convert to double or string before saving to the config file (wire a case structure to the type output of the vi and do the conversions in the dbl and string type cases) . Here also you should use different section, one for dbl another one for string. Here you use the standart Read Key vis from the configutaion file palette.

 

Ben64

Message 3 of 7
(3,357 Views)
Solution
Accepted by topic author Michael.Koppelgaard

The nice thing about an INI file is that it is "human-readable", all text with identifiers so you know what value goes with what name/identifier/variable.  Indeed, one of my earliest introductions to LabVIEW's INI functions was to try to figure out what someone else had done creating an INI file that was full of gibberish -- turns out they saved a Cluster by using Variant Flatten to String and writing out the string.  No idea what the values were.

 

Of course, the other nice thing about "readable" values is you can use a Text editor to change them, you don't need a LabVIEW program (unless, of course, someone has been "clever" and handed you a flattened variant, but we won't go there).

 

So given that what you want to write to the INI file is going to be text, either because you enter with, say, a Dbl and write it with a suitable format string (knowing you're going to read it back in with a similar format string and save it as a Dbl), you could come in with the value already in String form and simply use the Write String form of Write INI.  As others have noted, you could make a polymorphic VI to detect which input you are using, but it seems like a lot of trouble.  Why not make the decision at an earlier stage -- if the value comes in as a string, do a "Scan from String" to convert it to a Dbl, whereas if it comes in as a Dbl, you're done.

 

Bob Schor

Message 4 of 7
(3,334 Views)

Thank you all of you for your very fine answers. After considering I thing I will not make the function polymophic but keep it simple as suggested by Bob.

0 Kudos
Message 5 of 7
(3,271 Views)

You could always just make a Polymorphic VI.  It will require basically copies of what you already have, just with the different inputs/outputs.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 7
(3,256 Views)

maybe I should try just for fun and for learning 🙂

0 Kudos
Message 7 of 7
(3,232 Views)