06-10-2010 10:20 AM
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).
11-05-2012 11:27 AM
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
11-05-2012 01:00 PM
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.
11-05-2012 03:36 PM
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.
11-05-2012 04:02 PM
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.
11-06-2012 12:18 AM
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
11-06-2012 07:20 PM
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.
11-07-2012 10:21 AM
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.
11-07-2012 01:11 PM
Nice work! I'm glad you were able to figure that they secret was.