LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.NET type conversions in LabVIEW

Solved!
Go to solution

Hello,

I need to implement this simple data casting of c# objects in LV

 

object o = "MyString";
SqlString t1 = o as String      

 

 

How this can be done in LV??

 

0 Kudos
Message 1 of 11
(4,324 Views)

"To .NET Object.vi" in Connectivity>.NET.

 

Simply wire a string, and get a string object.

 

 

0 Kudos
Message 2 of 11
(4,317 Views)

Thanks for the reply

 

But in this scenario I have .Net string and I need .Net SqlString as attached below:

 

Capture.PNG

0 Kudos
Message 3 of 11
(4,307 Views)

Why don't you use the SqlString(string Data) constructor?

 

You can't cast a string to an SqlString, because the string object is not an SqlString.

0 Kudos
Message 4 of 11
(4,293 Views)

Thanks for reply.

 

When I compile c# code it works fine and there is no exception. 

There is implicit conversion possible and I need to force this in LV code.

https://msdn.microsoft.com/en-us/library/system.data.sqltypes.sqlstring.op_implicit(v=vs.110).aspx

 

0 Kudos
Message 5 of 11
(4,280 Views)
Message 6 of 11
(4,272 Views)

The problem is string object is returned by some other functions, I do not create it.

 

I could force object to string and back but i think this will work only for string type.

I have other situations where I need for it to behave like this simple c# code snipped where AS statement is used.

 

Capture.PNG

0 Kudos
Message 7 of 11
(4,264 Views)

You don't have access to c#- operators from LabVIEW, because they are a part of the C# language. With LabVIEW you access the .NET- Framework, not the C# langage features.

I think, your own solution is a good approach.

Greets, Dave
0 Kudos
Message 8 of 11
(4,250 Views)
Solution
Accepted by pawhan11

@daveTW wrote:

You don't have access to c#- operators from LabVIEW, because they are a part of the C# language. With LabVIEW you access the .NET- Framework, not the C# langage features.

I think, your own solution is a good approach.


I agree, not much alternatives in LabVIEW, besides doing it manually for each data type. If you really want this to be done automatically for all types, you'll need to make a .NET assembly in c#. You don't need VS or anything, there is a c# compiler included in .NET.

 

I you're really adventurous (=masochistic), you might be able to do it with .NET reflection, but I'm certain it won't be easy nor productive (=time consuming with small change of success). 

0 Kudos
Message 9 of 11
(4,238 Views)

Thanks for the interest in this topic.

 

Simple dll to handle conversions will do it. I try to avoid making to many dlls because it gets out of controll sooner or later.

 

The more i dig into how things can be solved in C# the more I realise how LV is limited... 

0 Kudos
Message 10 of 11
(4,232 Views)