Return value of Property Get when using enumerated type

J

jason

Not sure if there's any help available for this one!
In a class module named PlayingCard I have:

public enum enumColour
CdRed = 1
CdBlack = 2
end enum

private mColour as string

property let CardColour(byval clntColour as enumcolour)
select case clntColour
case CdRed,CdBlack
mColour = clntColour
case else
'error trapping goes heer
end select
end property

property get CardColour() as enumColour
CardColour = mColour
end property

Then in a standard module:

dim NewCard as PlayingCard

Sub CheckitOut
set NewCard = new PlayingCard
With NewCard
.cardcolour = CdRed
end with

debug.print "The Cards colour: " & newcard.cardcolour

end sub


What I'm left with in the immediate window is:
The Cards colour: 1

But what I want returned in the immediate window is
The Cards colour: CdRed

Am i doing something wrong? or is there no way around this using the above code.

Any help greatly appreciated
Jason
 
J

Jamie Collins

(e-mail address removed) (jason) wrote ...

A similar problem: how do you print the name of a variable?
Debug.Print <variable name> will print its value but what about its
name, surely it knows its own name?!

You will need another property:

public property get CardColourText() as string
CardColourText = GetCardColourText(mColour)
end property

Private function GetCardColourText( _
byval Colour as enumcolour _
) as String
dim sReturn as string
select case Colour
case CdRed
sReturn = "Red"
case CdBlack
sReturn = "Black"
case else
' error trapping goes here
end select
GetCardColourText = sReturn
end function

Jamie.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top