Results 1 to 4 of 4

Thread: How do I test the return value of a function which returns an object

  1. #1

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747

    How do I test the return value of a function which returns an object

    VB Code:
    1. Public Sub addOrderItem(orderItem As clsOrderItem)
    2.     If getOrderItem(orderItem.product) = nothing Then
    3.         colOrderItems.Remove orderItem.product
    4.     End If
    5.     colOrderItems.Add orderItem, orderItem.product
    6. End Sub
    7.  
    8. Public Function getOrderItem(product As String) As clsOrderItem
    9.     On Error GoTo errH
    10.     Set getOrderItem = colOrderItems(product)
    11.     Exit Function
    12. errH:
    13.     Set getOrderItem = Nothing
    14. End Function

    how do i test if the getOrderItem function returns nothing (ie if the orderItem isnt in the colOrderItems collection

    i figured that would work, but it says "Invalid use of object" and highlights the Nothing keyword

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Instead of '=', use 'Is'...
    VB Code:
    1. If getOrderItem(orderItem.product) Is Nothing Then
    2. '...
    3. End If

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Tried "If x Is Nothing Then" ?
    Please rate my post.

  4. #4

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    argh of course, thanx guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width