LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with variant block

Hi everibody

I am nephiew with labview and i am trying to use "to variant" block.

In the atteachment there is a picture of my VI.

Where am i wrong?!

 

Best regards

Giovanni

0 Kudos
Message 1 of 17
(3,477 Views)

Are you trying to convert the string to number?. There is a direct function "decimal string to number"

0 Kudos
Message 2 of 17
(3,461 Views)

muks is correct.

Furthermore you have connected the reference of the string and not its value.

0 Kudos
Message 3 of 17
(3,459 Views)

You are right but the problem is more complex.
This is only a short vi.
I am communicating with a PLC and to do that i have used a .NET library.
The problem is that the library gives me some data from the plc in a To string variable. See the atteachment.
Trhough the variable datatype i select the corrisponding case. In the case of boolean is not a metter. In the case of an int16 i don't know how i can do. I would like to make a different thing for all type of variables...
is it clear?!

in the atteachment there is the vi and two screenshot of it.

Download All
0 Kudos
Message 4 of 17
(3,444 Views)

You can't send a string value into a numeric control and expect it to understand the number.  You need to convert the string into a number using the String to Number functions in the String palette.

0 Kudos
Message 5 of 17
(3,405 Views)

To expand on what RavensFan wrote, if you are setting the value of a generic control - LabVIEW doesn't know what the 'type' of the value should be at run-time so the node displays a variant which is the most generic data type that you can read/write. LabVIEW doesn't do any sort of conversion on the data contained in the variant so it has to match the appropriate format for the control that you're setting the value property of. Therefore, what you wire into the 'value' property has to match the data type (which you then convert to a variant) of the control/indicator.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 6 of 17
(3,400 Views)

Ok... but if i have to convert a structure that comes from To String variable?!?!?!?

How can i make?!??!?!

0 Kudos
Message 7 of 17
(3,390 Views)

Hi nutty,

 

that is no "ToString variable" - it's a method node! (Do you ever read the context help in LabVIEW?)

 

No one forces you to use that method node…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 17
(3,381 Views)

You are getting the data type.  So your case structure is fine.  I would add comments to the cases for what each representation means.  But inside all you need to do for the I32 case is to just use Decimal String To Number and wire the output of that to your indicator.


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 9 of 17
(3,371 Views)

I agree with you, infact i have used that block.

 

The problem is... When, instead of a bool or a number, i receive a structure... how can i make to manage it?!?!

0 Kudos
Message 10 of 17
(3,353 Views)