+ Reply to Thread
Results 1 to 2 of 2

Class module problem/fun

  1. #1
    WhytheQ
    Guest

    Class module problem/fun

    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


  2. #2
    Bob Phillips
    Guest

    Re: Class module problem/fun

    Surely you would add another property to the class that determines whether
    an Ace is 1 or 11, and set that in the code.

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with googlemail if mailing direct)

    "WhytheQ" <[email protected]> wrote in message
    news:[email protected]...
    > 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
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1