NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

ActiveX/COM adapter - How to assign a Variant to hold an integer

Solved!
Go to solution

We are using a 3rd-party component and need to interface from TestStand using COM. The interface uses a Variant to pass data into various objects. We are unable to successfully pass an integer.

 

When the expected type contained in the Variant is a string or a double, the call is successful. When the expected type is an integer, the call fails. Passing in a Boolean will succeed, but only for 0 and -1.

 

How can we assign an integer value to a Variant?  We can only find Int64() convert functions.

Perhaps a function which returns an integer type can be used to convert a TestStand number (double) to an integer value, but so far, no luck.

 

 

0 Kudos
Message 1 of 6
(3,664 Views)

Hi Variant,

 

If you can retrieve it as a string, you can use the Val() function to convert to a number.

Humphrey H.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 6
(3,634 Views)

Our situation requires sending a Variant from TestStand which holds an integer. I am not an expert in the use of Variants (despite my tag name) but examples seem to indicate that the Variant type identifier needs to be set prior to making an assignment. I am assuming that TestStand does this for you based on the type that is being assigned. Since TestStand uses a 64-bit double as the storage for Numbers, I am guessing that the type identifier VT_R8 is being set. Special cases for Boolean and String are handled correctly but I can't seem to find a way to coerce a Variant assignment to specify an integer type when calling into the dll.

 

Now, if the Variant assignment of a double should be able to be extracted by the dll as an integer (using automatic type conversion provided by the Variant), then my premise may be incorrect and there may be a bug in the dll (no source).

0 Kudos
Message 3 of 6
(3,627 Views)
Solution
Accepted by topic author Variant

There is currently no way to pass a 32-bit integer in a VARIANT using the ActiveX/COM adapter. You can pass a 64-bit integer as you've probably already determined, but teststand does not natively store numbers as 32-bit integers and the ActiveX/COM adapter currently has no way to specify a conversion for a data type of VARIANT, so TestStand just stores the numeric type that it natively uses as a VARIANT.

 

In order to call this method from TestStand you will need to write a wrapper function that does the necessary parameter conversion and calls the method, and then call the wrapper function from TestStand instead.

 

-Doug

0 Kudos
Message 4 of 6
(3,622 Views)

Bummer! I was afraid that was the case.

 

Thanks Doug

0 Kudos
Message 5 of 6
(3,617 Views)

Update: The wrapper works just dandy!

 

Thanks again.

0 Kudos
Message 6 of 6
(3,608 Views)