キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

exchanging 2 D array between VBA and labview

As I noted in reply #5:

If you are building an app then you just need to enable the ActiveX server for the application, and that's done in the build specification

Specifically, it's done on the Advanced page of the build spec for the app. You must provide a name. This is the library name that you will reference in your VBA code (instead of the LabVIEW Type Library).

0 件の賞賛
メッセージ11/19
1,989件の閲覧回数

Hi there,

 

I'm having a related (although a little different) problem. I'm using my LabView VI as an ActiveX server, with excel VBA as the client. I want the user to be able to click a button in excel which will cause the contents of a string table control to display on a worksheet. I'm basically encountering some sort of type error, and using the following code I get "can't assign to array" for the GetControlValue line.

 

Sub LoadLoggerData()


Dim lvApp As LabVIEW.Application
Dim vi As LabVIEW.VirtualInstrument
Dim testTimeVals(1 To 2, 1 To 16)

Set lvApp = CreateObject("LabVIEW.Application")
viPath = lvApp.ApplicationDirectory + "\HorizonLogger\Bias.vi"

Set vi = lvApp.GetVIReference(viPath)   'Load the vi into memory

'This is where I get the error
testTimeVals = vi.GetControlValue("Test Times")

Sheet1.Cells(1, 8) = testTimeVals(0)(0)

'code simplified for clarity

End Sub

 I can, however, display a simple LabView string control in excel just fine using the same method:

 

Dim lvApp As LabVIEW.Application
Dim vi As LabVIEW.VirtualInstrument
Dim myStr As String

Set lvApp = CreateObject("LabVIEW.Application")
viPath = lvApp.ApplicationDirectory + "\HorizonLogger\Bias.vi"

Set vi = lvApp.GetVIReference(viPath)   'Load the vi into memory

myStr = vi.GetControlValue("testStr")


Sheet1.Cells(1, 5) = myStr


End Sub

 Any ideas? I'm sure there's a simple fix, but I'm fairly new to ActiveX and VBA.

 

Thank you,

Alex

0 件の賞賛
メッセージ12/19
1,873件の閲覧回数

You probably should have started a new thread for this.

 

What datatype is testTimeVals?  I see it is dimensioned as an array, but what type (strings, double, integers, ...)?

 

My guess is that you have a mismatch of datatypes.  First thing I would do is define that variable to be a Variant dataype.

0 件の賞賛
メッセージ13/19
1,869件の閲覧回数

Correct me if I'm wrong, but when you use Dim to declare a variable but don't give a type (i.e. I didn't write "As String"), VBA automatically uses the Variant type. So isn't testTimeVals already a Variant? I will give it a try anyway.

0 件の賞賛
メッセージ14/19
1,863件の閲覧回数

You might be right.  But I also remember some things that I think are carried over from older versions of basic like a variable with a $ is automatically a string.

 

If explicitly making it a variant doesn't work, then perhaps you need to define it as something else.  Perhaps if there was something like a LabVIEW.Array class to define the datatype.

 

I haven't done any VBA to LabVIEW transactions before, (some VBA with other applications objects like a DDE server.), so I am poking around in the dark a little bit on this.

0 件の賞賛
メッセージ15/19
1,859件の閲覧回数

RavensFan,

 

Ok, I've got some odd stuff going on. I get the same error as before when I try to use a 2d array of variants:

 

 

Dim testTimeVals(1 To 2, 1 To 16) As Variant

'I get "can't assign to array" here
testTimeVals = vi.GetControlValue("Test Times")

 

However, the following modifications allow the first cell of my labView string table to display just fine on the worksheet, but there's no way for me to access the rest of the table (I feel like this shouldn't work, but it does):

 

Dim testTimeVals As Variant

Sheet1.Cells(1, 8) = testTimeVals

 

I'm wondering if I need to do some sort of type conversion... That's what I'll look into next, I suppose. Let me know if anything else comes to mind!

Thanks,

 

Alex

 

 

0 件の賞賛
メッセージ16/19
1,850件の閲覧回数

Try setting TestTimeVals to be just a variant instead of an array of variants.  Do the equals.  Then see if there is anything meaninful that show up in the VBA variable.  If you can get that to work and see something, you might be able to figure out if there is a way to decode it.  If it was the LabVIEW side needing to decode, you could get a string and typecast it to something else like an array of U8's.  Or do something like Unflatten from String.  I don't know what would be the VB equivalent.

0 件の賞賛
メッセージ17/19
1,834件の閲覧回数

I figured it out! I used the To Variant labView function on my string table, then fed it into a hidden Variant control. On the VBA side, I declare my variable as a variant, then index it as an array after using GetControlValue(). It's not the tidy solution I was looking for, but it does appear to be working.

0 件の賞賛
メッセージ18/19
1,826件の閲覧回数

Nice work!  I'm glad you were able to figure that they secret was.

0 件の賞賛
メッセージ19/19
1,818件の閲覧回数