12-01-2022 03:43 AM - edited 12-01-2022 03:43 AM
I am using a COM-Interop in Lab-view, I have some functions that return an enum, I want to make a switch-case structure on this enum but I can't, but when I put an indicator to function output I see that the enum returned as expected.
so, my problem is I can't make this switch-case from my enum that exported from interop dll
12-01-2022 04:51 AM
any idea?
12-01-2022 04:58 AM
@Peterboshra wrote:
I am using a COM-Interop in Lab-view, I have some functions that return an enum, I want to make a switch-case structure on this enum but I can't, but when I put an indicator to function output I see that the enum returned as expected.
so, my problem is I can't make this switch-case from my enum that exported from interop dll
Can you give some example code? How does your COM-Interop work?
12-01-2022 05:17 AM
here is an example of a function return from the interface called that called "ITestList" it's return the eTestType enum
Namespace DataChannel.Interop
Public Interface ITestList
Function GetCount() As Integer
Function GetTestAt() As Integer
Function GetTestTypeAt(index As Integer) As eTestType
End Interface
End Namespace
12-01-2022 05:27 AM - edited 12-01-2022 05:27 AM
And where and how is eTestType defined? If it is a public definition then you can create an instance of it in LabVIEW. Otherwise not. But you need to know where it is defined, LabVIEW won't know on its own.
12-01-2022 05:36 AM
yes it's public and I can instance from it, but I can't link it with node output or switch-case I'm totally beginner 🙂
12-01-2022 06:32 AM
@Peterboshra wrote:
... when I put an indicator to function output I see that the enum returned as expected.
Can you expand on that? How does that look in LabVIEW? What do you expect and what do you get?
12-01-2022 06:55 AM
this is the output and the ring indicator on it I need to make a switch case from this enum output and according to the output the case switched and do some action
12-01-2022 07:21 AM
You probably need to use the "Coerce To Type" function (under palette: Programming → Numeric → Conversion"
https://www.ni.com/docs/en-US/bundle/labview/page/glang/coerce_to_type.html
12-01-2022 07:58 AM - edited 12-01-2022 07:59 AM
Ahhh now I understand. Since .net enums are really more sparse enums (even if they are fully consecutive) and LabVIEW doesn't have sparse enums, it translates them into a ring control. But a ring control only has string labels in the UI element, not as part of the data type. And therefore you can't select on that string as it is not part of the datatype.
If and only if, this enum is consecutive and not sparse (sparse meaning that it doesn't have a consecutive increasing numeric value corresponding to the enum string, but with some holes in it) you can right click on the ring control and select "Replace" and select an enum from the LabVIEW palette.
If you do that with a sparse enum, LabVIEW will reassign the enum values with consecutive increasing numbers and you get a mess as the numeric values don't correspond to the original numeric enum values anymore.