Error on trying to return value

AirforceMook

New Member
Joined
Sep 5, 2011
Messages
9
Code:
Private Function Get_Card() As card
 
    Dim unique As Boolean
    unique = False
    Dim thisCard As card
 
    While unique = False
 
        ' new card
        Set thisCard = New card
        Dim foundInLists As Boolean
        foundInLists = False
 
        ' check against dealer hand
        For Each dc In dealerCards
            If dc.Number = thisCard.Number And dc.Suit = thisCard.Suit Then
                foundInLists = True
            End If
        Next dc
 
        ' check against player hand
        For Each pc In playerCards
            If pc.Number = thisCard.Number And pc.Suit = thisCard.Suit Then
                foundInLists = True
            End If
        Next pc
 
        unique = Not foundInLists
 
    Wend
 
    Get_Card = thisCard
End Function

For some reason, Get_Card is 'Nothing' and causes the debugger to trip, selecting that line... even though I can do something like:

Code:
dim c as new card
msgbox(c.suit)

... elsewhere in the code without a problem. "Card" is my own class, it simply has a suit and number to represent standard playing cards. It has an initialize function that assigns a random suit and number to the card.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Fixed.

Had to use:

Set Get_Card = thisCard

... and when it is called later, also use set...

dim c as card
set c = Get_Card
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top