Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    May 2013
    Posts
    59
    Thanks
    34
    Thanked 6 Times in 6 Posts

    Create an Object from Data

    http://windowssecrets.com/forums/sho...ode+write+code

    Maud,

    I need your help again. The class module has been working perfectly but we need to expand it to include a cognitive scale. I would like to design it like:

    patient.cognitive followed by one of the following: .EyeOpening, .speech, .behavior, .motor, .strength, etc.

    I held my own to write the get and let procedures for cognitive but I am stuck on the attributes. Being a little over my head, can you point me in the right direction?

    Much appreciated
    Alexandra

  2. #2
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,640
    Thanks
    115
    Thanked 651 Times in 593 Posts
    Hi Alexandra,

    I would have liked to have seen your Get/Let Properties that you built but you can compare them to the code I have compiled. I still have the file that we created so I will go from there. <<4 Steps>>

    1. Create a new class module called ClsCognitive- The class module will hold all of the properties for the property cognitive (we will later build in the ClsPatient class module). Build the Let/Get Property procedures for each. Don't forget to declare the intermediate variables you use in your Get/Lets.

    ClsCognitive Class Module:
    Code:
    Private peo As String
    Private ptalk As String
    Private pact As String
    Private pmotion As String
    Private pstrong As String
    
    '-------------------------------------
    'PROPERTIES
    '-------------------------------------
    
    'EYE OPENING PROPERTY
    Public Property Get EyeOpening() As String
        EyeOpening = peo
    End Property
    Public Property Let EyeOpening(eyes As String)
        peo = eyes
    End Property
    
    'SPEECH PROPERTY
    Public Property Get Speech() As String
        Speech = ptalk
    End Property
    Public Property Let Speech(talk As String)
        ptalk = talk
    End Property
    
    'BEHAVIOR PROPERTY
    Public Property Get Behavior() As String
        Behavior = pact
    End Property
    Public Property Let Behavior(act As String)
        pact = act
    End Property
    
    'MOTOR PROPERTY
    Public Property Get Motor() As String
        Motor = pmotion
    End Property
    Public Property Let Motor(motion As String)
        pmotion = motion
    End Property
    
    'STRENGHT PROPERTY
    Public Property Get Strength() As String
        Strength = pstrong
    End Property
    Public Property Let Strength(strong As String)
        pstrong = strong
    End Property
    2. Assuming you still are using the ClsPatients class, Open the class module and declare the object Cognitive as ClsCognitive. Make sure the declaration is Public so procedures outside of the class can find it.

    ClsPatient Class Module:
    Code:
    Public Cognitive As ClsCognitive
    3. When an instance of ClsPatient is created, an new instance of ClsCognitive must also be created so that it will be available if needed. Add it to a Class_Initialize Procedure. One should already exist because we built the height and weight sub classes.

    ClsPatient Class Module:
    Code:
    'SET HEIGHT AND WEIGHT WHEN A NEW INSTANCE OF clsPATIENTS IS CREATED
    Private Sub Class_Initialize()
        Set height = New HeightMeasures
        Set Weight = New WeightMeasures
        Set Cognitive = New ClsCognitive
    End Sub
    4. Create a method to terminate the Cognitive class when the Patient class is terminated- Add to the Class_Terminate Procedure

    ClsPatient Class Module:
    [CODE]
    'TERMINATE THE VARIABLE BUT NOT THE PROPERTY
    Private Sub Class_Terminate()
    Set height = Nothing
    Set Weight = Nothing
    Set Cognitive = Nothing
    End Sub
    /CODE]

    Now using your new cognitive property in a standard module.

    Standard Module:
    Code:
    Public Sub CognitiveTest()
        Dim Patient As ClsPatient
        Set Patient = New ClsPatient
    '----------------------------------
    'USING THE LET PROPERTIES OF CLSCOGNITIVE CLASS
        Patient.Cognitive.Behavior = "Restless"
        Patient.Cognitive.EyeOpening = "Spontaneous"
        Patient.Cognitive.Motor = "Impaired"
        Patient.Cognitive.Speech = "Clear"
        Patient.Cognitive.Strength = "Weak"
    '----------------------------------
    'USING THE GET PROPERTIES OF CLSCOGNITIVE CLASS
        With Worksheets("Sheet1")
        .Cells(7, 2) = Patient.Cognitive.Behavior
        .Cells(8, 2) = Patient.Cognitive.EyeOpening
        .Cells(9, 2) = Patient.Cognitive.Motor
        .Cells(10, 2) = Patient.Cognitive.Speech
        .Cells(11, 2) = Patient.Cognitive.Strength
        End With
    End Sub
    class1.png

    class2.png

    I Have included the full Class Module with sample procedures on how to use them. I hope that helps if you need to create new properties and classes. That was a fun project.

    Maud
    Attached Files Attached Files

  3. The Following User Says Thank You to Maudibe For This Useful Post:

    Alouso (2014-10-02)

  4. #3
    Star Lounger
    Join Date
    May 2013
    Posts
    59
    Thanks
    34
    Thanked 6 Times in 6 Posts
    OMG! Thank you so much. I didn't mean for you to spend the time you must have put into this. I have examined your properties and the new class module. My Cognitive module was very similar to yours but I see where I went wrong back in the ClsPatient class module. I created a second Class_Terminate instead of just adding the termination code to the pre-existing one. I had also neglected to declare the new instance of the Cognitive object at the beginning of the class module. I made the changes and added some additional properties. All seems to be working well. My next venture is to add a functional status. I think I should be good from here.

    You help is very much appreciated.

    Thanks,
    Alex

Posting Permissions

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