Académique Documents
Professionnel Documents
Culture Documents
http://www.emagenit.com/FORTRAN DLL.htm
1 sur 3
24/12/2012 17:49
http://www.emagenit.com/FORTRAN DLL.htm
This strategy in mind, VBA procedures can be thought of as pre/post information processors for FORTRAN DLL routines. Excel in theory becomes the GUI dashboard that FORTRAN never had
VBA procedures know how to call a FORTRAN routine via a Declare statement. AN Example Declare statement is presented below.
Declare Sub FinVel Lib C:\Project\EngPrc.DLL (m1 As Double, v1i As Double, m2 As Double, vf As Double)
The name after Sub defines the procedure to call in FORTRAN, Lib is the path to the DLL and the ( )'s are its argument list.
Sub Velocity( ) Procedure gathers info for FinVel and outputs its calculations. Dim m1 As Double, v1i As Double, m2 As Double, vf As Double m1 = Range(B2).Value Read m1 mass value (kg) from cell B2 on active worksheet. v1i = Range(B3).Value Read velocity of m1 (m/s) from cell B3 on active worksheet. m2 = Range(B4).Value Read m2 mass value (kg) from cell B4 on active worksheet. Call FinVel(m1, v1i, m2, vf) Call FORTRAN FinVel Subroutine procedure. Use arguments m1, v1i, m2, vf to pass information to FORTRAN DLL procedure. Use vf to pass back answer. Range(B7).Value = vf Set cell B7 value on active worksheet to vf. End Sub
!FORTRAN Subroutine; Calculates final velocity of m1m2 collision (m/s). Subroutine FinVel(m1, v1i, m2, vf) Real(8) m1, v1i, m2, vf !MS$ ATTRIBUTES DLLEXPORT:: FinVel !MS$ ATTRIBUTES ALIAS: FinVel:: FinVel !Final velocity for both masses (stuck) vf = m1 * v1i / (m1 + m2) !Expression calculates final velocity of m1m2 (m/s). End Subroutine
Additional Pages Microsoft Excel Training Online Microsoft Excel Training Microsoft Excel Classes Microsoft Excel Courses Microsoft Excel Seminars Microsoft Excel Macros Microsoft Excel VBA Consulting Microsoft Excel Add-Ins
Copyright 2002-2012 EMAGENIT All Rights Reserved
2 sur 3
24/12/2012 17:49
http://www.emagenit.com/FORTRAN DLL.htm
3 sur 3
24/12/2012 17:49