Tech Tip: Calling NAG Routines From Excel
Users of the NAG Fortran DLLs will know from the supporting documentation and examples that it is perfectly possible to call the NAG routines from Excel. To help with this NAG supplies a set of 'Declare' statements which may be copied and pasted into your VBA module.
Typically there are a number of utilities that you might need to write or copy from the NAG examples in order to complete the necessary code. If you have access to the NAG statistical Add-Ins then these functions need not be replicated, simply reference the NAG_Library.xla supplied with the NAG Statistical Add-Ins. To do this obtain the VBA window in Excel from the Tools\Macro\Visual Basic Editor menus. In this Visual Basic Window use the Tools\References menus to establish a reference to NAG_Library.xla.
The following functions may be useful:
Public Sub AddNagMenu(NagSubMenu As String)
'Adds a submenu to the NAG Menu
End Sub
Sub Assemble(X, A)
' Take an argument X and ReDim a VB array A, copying the values
' contained in X into A.
' The first element of A may then be passed to NAG routines
' as an actual argument.
End Sub
Sub AssembleS(X, V)
' Take an argument X and ReDim a VB array vector V, copying the values
' contained in X into V.
' The first element of V may then be passed to NAG routines
' as an actual argument.
End Sub
Public Function ContextID(RoutineName As String) As Long
'Returns the ContextID for a NAG routine in the Help system
End Function
Public Sub DeleteNagMenu(NagSubMenu As String)
'Removes a submenu from the NAG menu
End Sub
Private Function dimension(myVariantArray) As Long
'Determines the number of dimensions of an array
'usually determining whether an array has two or one dimension.
End Function
For information on NAG's DLLs please visit http://www.nag.co.uk/numeric/NAGFortranDLLs.asp
For specific technical advice in using NAG's products, please contact our technical experts.
Return to Technical Tips & Hints index page.