LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get string value of Labview dll in VBA?

I'm now having problem to get output of Labview dll in Microsoft Excel VBA environment.

 

The labview dll function - Getstring below is the function I used in Excel VBA environment
/*!
 * GetString
 */
void __stdcall GetString(double x, double y, char String[], int32_t len);

 

I declared the dll as below

 

Public Declare sub GetString Lib "Filelocation..." (Byval X as double, Byval Y as Double, Byval StringData as string, Byval length as integer)

 

then I called the function in the VBA as below

 

Dim result as string

 

GetString(10,10,result,4)

 

Msgbox("the result is " & result)

 

when I run the code above, the result I got was actually  ?the result is" only, that means result has no value returned.

 

Could anyone help to share/advise what else I can do to get the value of the result?

0 Kudos
Message 1 of 3
(2,763 Views)

I'm not intimately familiar with VB, but if you're expecting the LabVIEW DLL to fill in the string, then you need to pass it ByRef instead of ByValue, and you need to allocate enough space for that string.  I'm assuming here that the len parameter is the string length, which you've set to 4, so you need to declare result as a string of at least 4 characters before passing it to the DLL.

0 Kudos
Message 2 of 3
(2,750 Views)

Ya...I have tried to use byref, it cause MS Excel not responding.

0 Kudos
Message 3 of 3
(2,744 Views)