Simply fortran graphics examples1/9/2023 ![]() The only error I get is in Excel the cells turning up with value error message. Had somewhat of battle when I did it with C/C but got that one working. When calling from VBA 7 or 64 bit seems necessary to include the keyword PtrSafe in the function declaration but that seemed fine. My computer set up is Windows 7 64 bit, 64 bit Excel 2010 and using compiler, Silverfrost Plato 4.5.1, tried both the release and debuggger modes. One thing that I found confusing where the references to “Declare Function ADD Lib “D:\Users\…\MathFunc\CheckMate\Win32\poly.dll” (A As Double, b As Double) As Double” poly.dll that is not the dll included in the zip file that one I believe is the MathFunc.dll. I have tried for a few hours to get his working on my machine but without success. Hi Doug, thank you for a very nice blog post. It really depends how comfortable you are working in Fortran, and how much modification is required to get it running reliably. If the Fortran code is not well written it might be easier to extract the algorithm from the code and than use that to write the VBA from scratch.Īn alternative worth considering is to write the front and back ends of the program in VBA then link to a compiled Fortran routine to do the main processing, as described in the blog article. That will leave the intermediate processing which should be fairly straightforward if the Fortran is well written, because the control and looping structures in Fortran and VBA are quite similar. I’d then write code to collect the input data and write the output from scratch. The approach I’d adopt is to find all the input and output required, which will require working through the code and an understanding of the process. Translating code that doesn’t work without understanding what it is doing sounds like asking for trouble to me. The four new MathFunc should now be available in the worksheet, just like the built in Excel functions: … adjusting the file path to the full path name for your file locations. ![]() Open the Visual Basic Editor (press Alt-F11), insert a new module, and enter the following lines of code:ĭeclare Function ADD Lib "D:\Users\.\MathFunc\CheckMate\Win32\poly.dll" (A As Double, b As Double) As Doubleĭeclare Function SUBTRACT Lib "D:\Users\.\MathFunc\CheckMate\Win32\poly.dll" (A As Double, b As Double) As Doubleĭeclare Function MULTIPLY Lib "D:\Users\.\MathFunc\CheckMate\Win32\poly.dll" (A As Double, b As Double) As Doubleĭeclare Function DIVIDE Lib "D:\Users\.\MathFunc\CheckMate\Win32\poly.dll" (A As Double, b As Double) As Double Open a new workbook and save it as MathFunc.xlsĢ. To make the four functions in MathFunc.dll available in Excel:ġ. When debugging is complete you can select “Release Win32” from the drop-down list at the top of the editor screen, and a release version of the dll will be created in \Release\Win32\. The program will create a file called MathFunc.dll in a subdirectory: \CheckMate\Win32\. Select Build – Build, or click the Build icon. Create a new dll project called MathFunc:īrowse for the MathFunc directory that you previously createdĦ. Start up the Plato IDE (the Silverfrost Fortran editor)ģ. Create a new directory called MathFunc at any convenient locationĢ. The examples will all be using Silverfrost Personal Fortran, which is available for download, and is free for non-commercial use.ġ. Later posts will look at creating more complex and useful programs, including passing arrays, and some catches in the handling of floating point numbers that need to be watched for. This post will look at creating four simple maths functions in Fortran, and linking them so that they are available in Excel, either to VBA routines, or directly from the spreadsheet. ![]() Fortran has features for the manipulation of arrays that are particulary useful for engineering and scientific analysis.The structure and syntax of Visual Basic is closer to Fortran than C. ![]() Many specialist engineering and scientific programs are only available in Fortran.The same advantages of increased security and performance may be obtained by linking to Fortran programs with the additional advantages: An earlier series of posts described how to link Excel to programs written in C or C .
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |