1

这与我在此错误上看到的其他问题不同。我的方法没有直接引用工作表;该方法存在并且可以正确编译,但是在引用它时出现运行时错误。细节:

我的 VBA 程序可以编译,但在我尝试访问特定方法时在运行时失败。我是否将方法设置为函数或属性获取似乎并不重要。

这是调用该方法的代码片段:

Function roots() As Variant ' array of variant(string, double or ratio): real roots only
  Dim fs() As MPolyFactor
  Dim f As Polynomial
  Dim result() As Variant
  Dim nFactors As Integer, i As Integer

  traceIn "entered roots; me = " & Me.toString() & "; f = " & stringify(f)
  On Error Resume Next
  ReDim result(1 To Me.degree) As Variant
    If Err.Number <> 0 Then
      trace "roots: redim result: " & Err.Number & ": " & Err.Description
      Err.Clear
    End If
  Err.Clear
  If Err.Number <> 0 Then
    trace "roots: Cannot clear Err: " & Err.Source & ": " & Err.Number & ": " & Err.Description
  End If
  fs = getPFactor
    If Err.Number <> 0 Then
      trace "roots: fs = getPFactor: " & Err.Source & ": " & Err.Number & ": " & Err.Description
      Err.Clear
    End If

(当然,该方法不止于此,但其余无关紧要)。

getPFactor 方法在物理上位于同一个类模块中但在上述之前,以:

Function getPFactor() As Variant ' mPolyFactor()
  traceIn "Entering getPFactor; me = " & Me.toString() & "; dim f(" & LBound(f) & " to " & UBound(f) & ")"

我的即时窗口的跟踪包括:

                        entered roots; me = x - 5; f = Nothing
                          roots: fs = getPFactor: VBAProject: 9: Subscript out of range

引用的跟踪函数位于代码模块中,该代码模块以:

Option Explicit
Public indent As Integer

Sub trace(str As String)
  Debug.Print Spc(indent); str
End Sub

Sub traceIn(str As String)
  trace (str)
  indent = indent + 2
End Sub

Sub traceOut(str As String)
  trace (str)
  indent = indent - 2
End Sub

有任何想法吗?我自己花了太多时间试图解决这个问题。

布鲁斯

4

0 回答 0