0

In the below code, nX = xMat.Rank returns the error "Invalid qualifier." Why? I'm using Excel 2010's built-in VBA editor:

Public Function polyReg(ByRef x() As Double, ByRef y() As Double) As Double()
  ' =============================
  Dim nX, nY, i, j As Integer
  Dim xMat() As Double
  nX = UBound(x)
  nY = UBound(y)
  ReDim xMat(1 To nX, 1 To order)
  ' =============================
  For i = 1 To order
    For j = 1 To nX
      xMat(j, i) = 1
    Next j
  Next i
  ' =============================
  nX = xMat.Rank
  ' =============================
  polyReg = y
  ' =============================
End Function

I looked at a few related posts that failed to address my concern:

Invalid Qualifier for String.Add in Outlook VBA

https://stackoverflow.com/questions/7889653/invalid-qualifier-error-in-vba

Invalid or Unqualified Reference

I have not found an answer to my question in Excel's VBA documentation.

Community
  • 1
  • 1
Mackie Messer
  • 1,126
  • 2
  • 8
  • 22

1 Answers1

1

I'm not a VB expert. If my answer below is incorrect, someone please notify me:

Visual Basic <> Visual Basic for Applications (Excel)... This is a hard lesson for me to learn. The Array.Rank function exists in VB but does not exist in VBA (Excel). What. A. Shame.

I'm tempted to ask another question with a similar answer, just because I know it will confound other programmers unfamiliar with VB and VBA. Is there any policy against asking questions to which you know the answer? (Topic of theoretical question: Try/Catch? Only VB. VBA (Excel) uses On Error.)

Mackie Messer
  • 1,126
  • 2
  • 8
  • 22
  • 1
    You're answer is correct. Array's and strings are not objects in VBA and do not have member functions. Get used to disappointment. Answering your own question is encouraged if you found a solution. Asking a question that you know the answer to is ok (check Meta-Stackoverflow first) as long as it hasn't already been asked. – cheezsteak Sep 10 '14 at 20:53