W
WhytheQ
Maybe you can help?
About a year ago I gave up on a little project because I got stuck!!
The aim of the project was to practice using Class modules to gain a
bit of confidence and hopefully be able to use them in my job as I've
heard they can be very powerful.
The first class was called ClsCard and is supposed to represent a
playing card e.g the Jack of Hearts etc.The code is below.
Please let me know if you think the logic of my code is ok, I usually
overconplicate things.
The problem i had was what to do with the ace, as the value can be
either low 1 or high11- how could a class module handle this??
Any encouragment greatly appreciated.
(Also any usefull literature/articles of the use of Class Modules would
be great)
Jason.
PASTE INTO A CLASS MODULE CALLED ClsCard:
Option Explicit
Private mCardSuit As String
Private mCardValue As Integer
Private mCardColour As String
Private mCardName As String
Private mIsPictureCard As Boolean
Public Enum enumName
two = 2
Three = 3
Four = 4
Five = 5
Six = 6
Seven = 7
Eight = 8
Nine = 9
Ten = 10
Jack = 11
Queen = 12
King = 13
Ace = 14
End Enum
Public Enum enumAces
High = 1
Low = 2
Udecided = 3
End Enum
Public Enum enumSuitName
Club = 1
Diamond = 2
Heart = 3
Spade = 4
End Enum
'********CARD'S NAME PROPERTY****************
'********************************************
Property Let CardName(ByVal clientCardName As enumName)
Select Case clientCardName
Case Is = two
mCardName = "Two"
mCardValue = 2
mIsPictureCard = False
Case Is = Three
mCardName = "Three"
mCardValue = 3
mIsPictureCard = False
Case Is = Four
mCardName = "Four"
mCardValue = 4
mIsPictureCard = False
Case Is = Five
mCardName = "Five"
mCardValue = 5
mIsPictureCard = False
Case Is = Six
mCardName = "Six"
mCardValue = 6
mIsPictureCard = False
Case Is = Seven
mCardName = "Seven"
mCardValue = 7
mIsPictureCard = False
Case Is = Eight
mCardName = "Eight"
mCardValue = 8
mIsPictureCard = False
Case Is = Nine
mCardName = "Nine"
mCardValue = 9
mIsPictureCard = False
Case Is = Ten
mCardName = "Ten"
mCardValue = 10
mIsPictureCard = False
Case Is = Jack
mCardName = "Jack"
mCardValue = 10
mIsPictureCard = True
Case Is = Queen
mCardName = "Queen"
mCardValue = 10
mIsPictureCard = True
Case Is = King
mCardName = "King"
mCardValue = 10
mIsPictureCard = True
Case Is = Ace
mCardName = "Ace"
mCardValue = 11
mIsPictureCard = False
End Select
End Property
Property Get GetCardName() As String
GetCardName = mCardName
End Property
'
''******CARD'S ISPICTURECARD PROPERTY:read only*****
''**************************************************
Property Get IsPictureCard() As String
IsPictureCard = mIsPictureCard
End Property
'
''***********CARD'S SUIT PROPERTY*******************
''**************************************************
Property Let CardSuit(clientSuitName As enumSuitName)
Select Case clientSuitName
Case Is = 1
mCardSuit = "Clubs"
mCardColour = "Black"
Case Is = 2
mCardSuit = "Diamonds"
mCardColour = "Red"
Case Is = 3
mCardSuit = "Hearts"
mCardColour = "Red"
Case Is = 4
mCardSuit = "Spades"
mCardColour = "Black"
End Select
End Property
Property Get GetCardSuit() As String
GetCardSuit = mCardSuit
End Property
'
''********CARD'S COLOUR PROPERTY:read only***********
''***************************************************
Property Get GetCardColour() As String
GetCardColour = mCardColour
End Property
'
''******CARD'S VALUE PROPERTY:read only**************
''***************************************************
Property Get GetCardValue() As Integer
GetCardValue = mCardValue
End Property
'**********************************
'**********************************
AND PASTE INTO A NORMAL MODULE:
Dim myCard As ClsCard
Sub ShowTheCard()
Set myCard = New ClsCard
With myCard
.CardName = two
.CardSuit = Diamond
End With
MsgBox "Card Name: " & myCard.GetCardName & vbCr & _
"Card Colour: " & myCard.GetCardColour & vbCr & _
"Card Suit: " & myCard.GetCardSuit & vbCr & _
"Is Picture Card: " & myCard.IsPictureCard & vbCr &
_
"Card Value: " & myCard.GetCardValue
Set myCard = Nothing
End Sub
About a year ago I gave up on a little project because I got stuck!!
The aim of the project was to practice using Class modules to gain a
bit of confidence and hopefully be able to use them in my job as I've
heard they can be very powerful.
The first class was called ClsCard and is supposed to represent a
playing card e.g the Jack of Hearts etc.The code is below.
Please let me know if you think the logic of my code is ok, I usually
overconplicate things.
The problem i had was what to do with the ace, as the value can be
either low 1 or high11- how could a class module handle this??
Any encouragment greatly appreciated.
(Also any usefull literature/articles of the use of Class Modules would
be great)
Jason.
PASTE INTO A CLASS MODULE CALLED ClsCard:
Option Explicit
Private mCardSuit As String
Private mCardValue As Integer
Private mCardColour As String
Private mCardName As String
Private mIsPictureCard As Boolean
Public Enum enumName
two = 2
Three = 3
Four = 4
Five = 5
Six = 6
Seven = 7
Eight = 8
Nine = 9
Ten = 10
Jack = 11
Queen = 12
King = 13
Ace = 14
End Enum
Public Enum enumAces
High = 1
Low = 2
Udecided = 3
End Enum
Public Enum enumSuitName
Club = 1
Diamond = 2
Heart = 3
Spade = 4
End Enum
'********CARD'S NAME PROPERTY****************
'********************************************
Property Let CardName(ByVal clientCardName As enumName)
Select Case clientCardName
Case Is = two
mCardName = "Two"
mCardValue = 2
mIsPictureCard = False
Case Is = Three
mCardName = "Three"
mCardValue = 3
mIsPictureCard = False
Case Is = Four
mCardName = "Four"
mCardValue = 4
mIsPictureCard = False
Case Is = Five
mCardName = "Five"
mCardValue = 5
mIsPictureCard = False
Case Is = Six
mCardName = "Six"
mCardValue = 6
mIsPictureCard = False
Case Is = Seven
mCardName = "Seven"
mCardValue = 7
mIsPictureCard = False
Case Is = Eight
mCardName = "Eight"
mCardValue = 8
mIsPictureCard = False
Case Is = Nine
mCardName = "Nine"
mCardValue = 9
mIsPictureCard = False
Case Is = Ten
mCardName = "Ten"
mCardValue = 10
mIsPictureCard = False
Case Is = Jack
mCardName = "Jack"
mCardValue = 10
mIsPictureCard = True
Case Is = Queen
mCardName = "Queen"
mCardValue = 10
mIsPictureCard = True
Case Is = King
mCardName = "King"
mCardValue = 10
mIsPictureCard = True
Case Is = Ace
mCardName = "Ace"
mCardValue = 11
mIsPictureCard = False
End Select
End Property
Property Get GetCardName() As String
GetCardName = mCardName
End Property
'
''******CARD'S ISPICTURECARD PROPERTY:read only*****
''**************************************************
Property Get IsPictureCard() As String
IsPictureCard = mIsPictureCard
End Property
'
''***********CARD'S SUIT PROPERTY*******************
''**************************************************
Property Let CardSuit(clientSuitName As enumSuitName)
Select Case clientSuitName
Case Is = 1
mCardSuit = "Clubs"
mCardColour = "Black"
Case Is = 2
mCardSuit = "Diamonds"
mCardColour = "Red"
Case Is = 3
mCardSuit = "Hearts"
mCardColour = "Red"
Case Is = 4
mCardSuit = "Spades"
mCardColour = "Black"
End Select
End Property
Property Get GetCardSuit() As String
GetCardSuit = mCardSuit
End Property
'
''********CARD'S COLOUR PROPERTY:read only***********
''***************************************************
Property Get GetCardColour() As String
GetCardColour = mCardColour
End Property
'
''******CARD'S VALUE PROPERTY:read only**************
''***************************************************
Property Get GetCardValue() As Integer
GetCardValue = mCardValue
End Property
'**********************************
'**********************************
AND PASTE INTO A NORMAL MODULE:
Dim myCard As ClsCard
Sub ShowTheCard()
Set myCard = New ClsCard
With myCard
.CardName = two
.CardSuit = Diamond
End With
MsgBox "Card Name: " & myCard.GetCardName & vbCr & _
"Card Colour: " & myCard.GetCardColour & vbCr & _
"Card Suit: " & myCard.GetCardSuit & vbCr & _
"Is Picture Card: " & myCard.IsPictureCard & vbCr &
_
"Card Value: " & myCard.GetCardValue
Set myCard = Nothing
End Sub