Simpleton object returning Array problem

  • Thread starter Thread starter Callisto
  • Start date Start date
C

Callisto

Hi All!
##### I have a class clsQProductItem with function GetAllFromInvoice:

Friend Function GetAllFromInvoice(ByVal Invoice As String) As
clsQProductItem()
' Dim retObject() As clsQProductItem = New
clsQProductItem

Dim DataConn As New DataConn
Dim DT As New DataTable
Dim iRowNum As Integer

'Step1: Get all productItems belonging to Invoice
Try
DT = DataConn.RunCmd("Select * from '" & TableName & "'
where invoice = '" & Invoice & "'")
Dim retObject(DT.Rows.Count) As clsQProductItem
'retObject = New clsQProductItem
While Not (DT.Rows(iRowNum).HasErrors)
With retObject(iRowNum)
.ProductItemID =
DT.Rows(iRowNum).Item("ProductItemID").ToString
.Product =
DT.Rows(iRowNum).Item("Product").ToString
.Invoice = Invoice
.Quantity =
DT.Rows(iRowNum).Item("Quantity").ToString
End With
iRowNum += 1
End While
Return retObject
Catch ex As Exception
EventLog1.WriteEntry("Error in cls" & TableName &
".GetAllFromInvoice: " & ex.Message)
End Try


End Function

###### Trying to call this function from a Form:

Dim QProd() As clsQProductItem = New clsQProductItem() {}
QProd = DirectCast(QProd.GetAllFromInvoice(CurrentQinvoice),
clsQProductItem())

###### I get a squiggly line with message 'GetAllFromInvoice' is not a
member of 'System.Array'

###### Tried this also, gives same error

Dim QProd() As clsQProductItem = New clsQProductItem() {}
QProd = QProd.GetAllFromInvoice(CurrentQinvoice)
 
###### Trying to call this function from a Form:

Dim QProd() As clsQProductItem = New clsQProductItem() {}
QProd = DirectCast(QProd.GetAllFromInvoice(CurrentQinvoice),
clsQProductItem())

###### I get a squiggly line with message 'GetAllFromInvoice' is not a
member of 'System.Array'

That's because QProd is an array reference wheras the GetAllFromInvoice is
an instance method of a clsQProductItem object. I suggest you make the
method shared and call it using the class name. By the way, the cast is
not necessary.


Shared Function GetAllFromInvoice(...) As clsQProductItem()
...
End Function

Dim QProd() As clsQProductItem =
clsQProductItem.GetAllFromInvoice(CurrentQInvoice)


--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Back
Top