0

Situation:

My VBA program compiles, but fails at runtime when I try to access a specific method. It doesn't seem to matter whether I set the method up as a function or a property get.

Here is the code fragment which calls the method:

******

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
********

(the method continues beyond this, of course, but the rest is irrelevant).

The getPFactor method, which is physically in the same class module but before the above, starts with:

******

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

My immediate window's trace includes:
******

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

******

The tracing functions referenced are in a code module which starts with:

******

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
*******

Any ideas? I've been trying to figure this out for far too many hours on my own.

Bruce

2
Contributors
1
Reply
19
Views
3 Years
Discussion Span
Last Post by WetCoastLife
0

Your Immediate window says F = Nothing.
Line 2 in Function getPFactor(), it appears you're trying to get LBound and Ubound of Nothing.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.