That being said, what do you mean by *install* a DLL? Can the user just copy the DLL to the directory they are running in? I am thinking I need:.xls with VBA code to interface to fortran.dll that is the bridge between VBA and fortan.dll that runs the fortran
All of them would be in the same directory. Does this make sense?
Either the same directory, or better put the two dlls in the System32 directory (or another on the search path) so they can be called from anywhere.
Overall, how difficult is it to interface the fortran to VBA? There are a lot of pretty good codes done under air force contract that are in the public domain. I think it would be useful to have an Excel interface to them.
Not very difficult, once you have got the compiler settings right, which the blog post should cover. Really all you have to do is:
- Convert the Excel data into a form acceptable to Fortran, then pass it to the dll.
- Add a declare statement at the top of the module, or in a separate module, to tell VBA where the dll function is
- Add some code to the Fortran to receive data and pass it back in a suitable form. Typically all you need to do is write any output to an array passed by reference, then the VBA can access that data and write it to the spreadsheet, or whatever you want to do with it.
The main thing with the VBA code is to make sure that everything that is passed to the Fortran routine and back is the right data type, and that arrays are exactly the right size. If you pass an array to the Fortran and the dll writes outside the bounds of the array, you won't get a polite message saying you can't do that, it will just crash, or worse it will act like everything is OK and then crash when you are half way through a demonstration with a potential client.
Doug Jenkins
Interactive Design Services