FIX: Ref to NPV / IRR / MIRR Gives Undefined Functions ErrorLast reviewed: October 30, 1997Article ID: Q101245 |
3.00
WINDOWS
kbprg kbbuglist
The information in this article applies to: - Professional Edition of Microsoft Visual Basic programming system for Windows, version 3.0
SYMPTOMSIf you try to run an application that contains a reference to the NPV, IRR, or MIRR financial function, Visual Basic for Windows generates this error:
Reference to undefined Function or Array CAUSEVisual Basic does not recognized these as Visual Basic functions because they were incorrectly referenced in the financial DLL file (MSAFINX.DLL) that ships with Visual Basic version 3.0.
WORKAROUNDTo workaround the problem, declare the NPVC, IRRC, and MIRRC functions located in MSAFINX.DLL and alias them as NPV, IRR, and MIRR respectively. The code provided in the More Information section below demonstrates how to declare and call these functions.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem has been corrected in Visual Basic version 4.0.
MORE INFORMATIONThe following example shows how to use the NPV function. It is based on the example shown in the Visual Basic Help menu, but it also includes the declarations for the NPV, IRR, and MIRR financial functions. Without the declarations for these functions, the example will fail, giving a "Reference to undefined Function or Array" error.
Steps to Work Around the Problem
MsgBox (Str$(Err)) Exit Function End Function ' Enter the following Function statement on one, single line: Function MIRR (values() As Double, ByVal finance As Double, ByVal reinvest As Double) As Double On Error GoTo MirrErr iArgMin% = LBound(values) cArg% = UBound(values) - iArgMin% MIRR = MIRRC#(values(iArgMin%), cArg%, finance, reinvest) Exit FunctionMirrErr: MsgBox (Str$(Err)) Exit Function End Function Function NPV (ByVal Rate1 As Double, values() As Double) As Double On Error GoTo NpvErr iArgMin% = LBound(values) cArg% = UBound(values) - iArgMin% NPV = NPVC#(Rate1, values(iArgMin%), cArg%) Exit FunctionNpvErr: MsgBox (Str$(Err)) Exit Function End Function
Sub Form_Click () Static Values(5) As Double ' Set up array. Fmt = "###,##0.00" ' Define money format. Guess = .1 ' Guess starts at 10%. RetRate = .0625 ' Set fixed internal rate. Values(0) = -70000 ' Business start-up costs. ' Positive cash flows reflecting income for four successive years. Values(1) = 22000: Values(2) = 25000 Values(3) = 28000: Values(4) = 31000 NetPVal = NPV(RetRate, Values()) ' Calculate net present value. Msg = "The net present value of these cash flows is " Msg = Msg & Format(NetPVal, Fmt) & "." MsgBox Msg ' Display net present value. End Sub
|
Additional reference words: buglist3.00 3.00 errmsg fixlist4.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |