From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

exchanging 2 D array between VBA and labview

I have a project : half part is VBA writen, half part is  Labview coded. Both parts are writen to operate manually. The first one prepares data and charts them on charts sheets, the second one smooths data with ready made labview curves fitting VIs. So I want operator could use them seamless, that means calling labview from VBA 2007 code collecting X,Y data into a 2 D array, then send it to labview DLL smooth the curves and send back an array with smoothed data to excel through VBA.

My concern is how to declare 2D array parameters in VBA  and in Labview in order to work fine (array of variants or doubles, parameters declared by ref or by val)

I have seen similar topics in NI forum but they dealt with VB.net and not VBA .

 

I run office 2007 and labview 2009 full dev. system with application builder.

 

Regards

0 Kudos
Message 1 of 19
(4,001 Views)

I know that labview side there is infact a way to trigger macro's.  Do you actually need to be able to interact with the folder once it is full of data?

 

If not then save a copy of the file as .html then you can use labview to display it too!  Utterly seemless.

 

Although, the alternative is use one or the other.  Is there a reason the whole thing cant be done in vba?

 If there is then is there a reason the whole thing can't be done in labview?

 

I think you may be overcomplicating the program this time around.

 

I've been wrong before though!

_________________________________________________________________________________________________

That glass?

Thats glass is neither half full or half empty....
Its twice the size it needs to be
0 Kudos
Message 2 of 19
(3,988 Views)

I would agree that I would like to know more specifics as to what you're doing to see if you can handle it one environment only. That said, an alternative to using DLLs is to use the ActiveX interface for LabVIEW. Have you taken a look at this? With the ActiveX server you could do something like this in VBA:

 

Sub SampleArray()
    Dim Data(1 To 3, 1 To 4)
    Dim row As Integer
    Dim col As Integer
    Dim lvApp As LabVIEW.Application
    Dim vi As VirtualInstrument


    For row = LBound(Data, 1) To UBound(Data, 1)
        For col = LBound(Data, 2) To UBound(Data, 2)
            Data(row, col) = Cells(row, col)
        Next col
    Next row

    Set lvApp = New LabVIEW.Application
    Set vi = lvApp.GetVIReference("C:\temp\2D_VBA_Test.vi")
    vi.FPWinOpen = True
   
    vi.SetControlValue "Array", Data

   

    <cleanup code here>

End Sub

(Note: cleanup code refers to closing references, etc)

0 Kudos
Message 3 of 19
(3,978 Views)

Thank you for the answers.

The examples provided with labview for ActiveX exchanges are not very clear. I want to use labview as ActiveX server and Excel through VBA as client.

VBA code as to launch ActiveX server and as far as I am right in these sample programs it is labview Vi which launches an excel session.

I have no idea of creating and exposing classes, methods or properties needed in VBA from my Labview VI which was at the beginning a standalone application.

 

nice regards

0 Kudos
Message 4 of 19
(3,951 Views)

bassevellois wrote:

Thank you for the answers.

The examples provided with labview for ActiveX exchanges are not very clear. I want to use labview as ActiveX server and Excel through VBA as client.


There's only one example that I know of that ships with LabVIEW and it shows how to access LabVIEW from VB using LabVIEW's ActiveX server. It opens a VI and runs it. Doing it from VBA is very similar. You want to add the reference to the ActiveX Server in your VBA project. If you're controlling the LabVIEW development environment directly, then the library to include in your list of references will be "LabVIEW x.x Type Library". If you are controlling a LabVIEW-build app, then the library name will be whatever you specified when you built the app. 

 


I have no idea of creating and exposing classes, methods or properties needed in VBA from my Labview VI which was at the beginning a standalone application.

I don't quite understand what you are referring to. The ActiveX Server in LabVIEW and a LabVIEW-built app are pre-defined. You do not export anything from your LabVIEW VI. The available properties and methods are a function of the LabVIEW ActiveX Server, not of your VI. 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. 

 

 

How to reproduce my example:

  1. Make sure you've enabled the ActiveX Server in LabVIEW. 
  2. Download the attached 2D_VBA_Test VI to your C:\Temp folder. You can save it anywhere, but you'd have to change the path in the Excel VBA macro.
  3. Download the attached Excel workbook.
  4. Open the workbook and click the button. If LabVIEW is not running it should launch LabVIEW, and open the VI and populate the front panel array with the values from the spreadsheet. 

 

Download All
0 Kudos
Message 5 of 19
(3,935 Views)

Thank you smecurio_fc but I can't open the Xl workbook, Excel tells me the file is corrupted (the macro code module concealed in the workbook is not loaded when Excel fixes it) .

May you try if you can to save it in new Excel binary format xlsb.

 

regards

0 Kudos
Message 6 of 19
(3,919 Views)

Smercurio's .xls file opens just fine for me.

 

Perhaps it is a security setting you have set in Excel that prevents you from opening files with macro code.

 

I don't know what the "new Excel binary format xlsb" you are talking about is.  Whatever it is sounds extremely proprietary and unlikely that most Excel users would be able to open it.

0 Kudos
Message 7 of 19
(3,913 Views)
I would agree that it sounds like a security setting. It also sounds like you have Excel 2007. I created mine with Excel 2003, so I haven't a clue as to what you need to do in Excel 2007.
0 Kudos
Message 8 of 19
(3,906 Views)

It's allright now on another PC which warned me of security settings then I turned them to low But it is weird for my own PC on which I work on VBA modules coding,  security settings are turned low by default. Now it doesn't matter I have saved it and have sent it by email to my own PC and it works fine

Thank you for your help and I will work around to adapt it to my concern

 

0 Kudos
Message 9 of 19
(3,883 Views)

Now it is an other question about the same ActiveX Vi compiled as an exe for installing on few computers : How can I call it from VBA because it has no more the .VI extension (of course it is exe) and it is not seen by VBA as labview component with all its properies and so on.

What is the trick ?

I have tried to find out this afternoon but I have found not a single bit of information on the subject.

 

Regards

 

 

0 Kudos
Message 10 of 19
(3,862 Views)