LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String to variant

Hello LabVIEW experts,

 

i want to convert a string to variant for a Property node which i use indipendent from the function. If i use the "to variant" function with an i32 as input, i am receiving the value which i need. But if I use a string as input it is converting it to the variant with the value "1" always. And the characters needed to be deleted from the variant. 

Also if i use the function Flattend string to variant i am receiving an error code. I searched in different forums but did not find an example for Flattened String to Variant.

 

IbTkmk52_0-1706621734899.png

 

The probe 3 returns the value without characters. I need this exactly with a string as input. I hope i was understandable.

 

Best regards

 

 

 

0 Kudos
Message 1 of 11
(840 Views)

Hi lb,

 


@IbTkmk52 wrote:

I need this exactly with a string as input. I hope i was understandable.


No, I don't understand your problem!

 

  • A string is something different than an I32 value!
  • They both result in different representations in the variant.
  • FlattenToString also gives a different result than ToVariant.

So why do you to convert?

What is your source data?

What is the (expected) resulting data?

Can you provide exact examples? (Best is a VI with some constants or controls with default values!)

Your image is lacking the information about the data in your controls...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(836 Views)

Hi @GerdW,

 

i attached a example vi. The main thing is that i need to convert a string value to a variant without charachters ("").

I explained it in the block diagram of the VI with a comment. Hopefully this will help.

0 Kudos
Message 3 of 11
(832 Views)

@IbTkmk52 wrote:

The main thing is that i need to convert a string value to a variant without charachters ("").


You are storing an ASCII value to represent your number.  This is completely different than a "flattened string".  So you need to first use Decimal String To Number to convert to an I32 and then you can convert to a variant.


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 4 of 11
(823 Views)

Hi lb,

 


@IbTkmk52 wrote:

The main thing is that i need to convert a string value to a variant without charachters ("").


When you don't want those quotation marks inside the variant then you should NOT convert a string to a variant!

See this:

Why do you need a variant in the end?

What's the problem with quotation marks inside the variant display???

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 11
(820 Views)

Hi Gerd, 

 

i am using the CANoe 17 Type Library to set a environment variable in CANoe. And the input of setting the value is a variant. Now in my case i have environment variables with the datatype of a uint32 or also a char. If i want to use the function i need to convert my string into a variant. That is the simple reason. 

 

If i convert the string first into a number than it will also not work for different characters like "HelloWorld", ... The input of the function (string) is a string not a decimal string. 

 

BR

0 Kudos
Message 6 of 11
(806 Views)

Hi @crossrulz,

 

this would work if i use the string as a decimal string value. But the input can also be a character value, for e.g. "HelloWorld".

 

BR

0 Kudos
Message 7 of 11
(805 Views)

Hi lb,

 


@IbTkmk52 wrote:

this would work if i use the string as a decimal string value. But the input can also be a character value, for e.g. "HelloWorld".


The quotation marks are only shown inside the variant indicator, they aren't part of the actual data inside the variant...

 

What happens when you send a string to your CANoe tool?

Best regards,
GerdW


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

Hi Gerd,

it is sending the value with the quotation marks and CANoe returns the value "1" back. So the TPL from ActiveXControl is sending the value also as a "1" with quotation marks.

0 Kudos
Message 9 of 11
(773 Views)

Hi IbTkmk52,

 

I think you are mislead by how the variant displays its value.

The quotation marks are only here to indicate that the value in between is a string.

They are not part of the value, these are just the variant's cosmetics.

 

 


@IbTkmk52 wrote:

it is sending the value with the quotation marks and CANoe returns the value "1" back. So the TPL from ActiveXControl is sending the value also as a "1" with quotation marks.


How do you know the returned value has quotation marks in its value? Did you convert your variant back to an actual string?

 

raphschru_0-1706625946849.png

 

Regards,

Raphaël.

Message 10 of 11
(760 Views)