Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Return value of Property Get when using enumerated type

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Return value of Property Get when using enumerated type - HELP!!

(jason) wrote ...

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


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.

--
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Return value of Property Get when using enumerated type - HELP!!

cheers Jamie - that extra prperty is the approach i've ended up taking.

Jason

(Jamie Collins) wrote in message . com...
(jason) wrote ...

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


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.

--

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Property Let: assign return value of Double when passing String Tetsuya Oguma Excel Discussion (Misc queries) 1 March 3rd 06 08:01 AM
Type in letter return word Marta Excel Worksheet Functions 5 September 10th 05 10:51 PM
Enumerated constants defined where? JW[_5_] Excel Programming 6 July 23rd 04 10:47 AM
Using Property Let with a Type as member of a Class Ken Dahlberg Excel Programming 5 December 21st 03 05:57 AM
How to find what object type is returned from Selection property ? Krzysztof Klimczak[_3_] Excel Programming 1 October 2nd 03 11:33 PM


All times are GMT +1. The time now is 06:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"