*

Form Code for Aggregation Mini-Lecture: Day 2

Option Explicit
Private Const OK As Integer = vbOKOnly
Private Const MessageTitle As String = "Pet Care Error"
Private strPetType As String
Private intTypeCare As Integer
Private WithEvents PetCare As clsPetCare

Private Sub cmdCancel_Click()
    Unload Me
End Sub
Private Sub cmdOK_Click()
    'client-side validation - don't want bad data going in
    If ValidatedInput Then
        'do something here
        Set PetCare = New clsPetCare 'IUnknown::AddRef
        With PetCare
            .PetType = strPetType
            .CareType = optPetCare(intTypeCare).Caption
            Select Case intTypeCare
                Case 0 'feed
                    MsgBox .Food, OK, "Pet Care"
                Case 1 'clean
                    MsgBox .Cleaner, OK, "Pet Care"
                Case 2 'exercise
                    MsgBox .Exercises, OK, "Pet Care"
                Case 3 'attention
                    MsgBox .Attentions, OK, "Pet Care"
            End Select
        End With
        Set PetCare = Nothing 'IUnknown::Release
    End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
    'release the form object
    Set frmPetCareClass = Nothing
End Sub
Private Function ValidatedInput() As Boolean
    'this procedure will need to be customized for whatever front-end
    Dim blnValidated As Boolean
    Dim obPetCare As OptionButton
    'check to see if pet selected
    'if not, alert user, set validated flag to false, move cursor to pet list, and exit procedure
    If lstPetType.ListIndex < 0 Then
        MsgBox _
            "You must select a pet before continuing", _
            OK, _
            MessageTitle
        lstPetType.SetFocus
        blnValidated = False
        GoTo ExitHere

    'if so, capture type for next check and set validated flag to true
    'move on to next check
    Else
        strPetType = lstPetType.Text
        blnValidated = True
    End If
    'check to see if care type selected
    For Each obPetCare In optPetCare
        'if so, leave the validated flag at true and exit
        If obPetCare.Value = True Then
            'release the optionbutton object
            Set obPetCare = Nothing
            GoTo ExitHere
        End If
    Next obPetCare
    'if not, alert user with customized message, set validated flag to false and exit
    MsgBox _
        "You must select a type of care for your " _
            & strPetType & " before continuing", _
        OK, _
        MessageTitle
        blnValidated = False
        'release the optionbutton object
        Set obPetCare = Nothing
    GoTo ExitHere
ExitHere:
    'single out
    ValidatedInput = blnValidated
End Function

Private Sub optPetCare_Click(Index As Integer)
    intTypeCare = Index
End Sub

Private Sub PetCare_PetCareAdvised(TypeCare As String)
    'reset values
    lstPetType.ListIndex = -1
    optPetCare(intTypeCare) = False
End Sub

Internet Content Rating Association

Alrak's Course Resources ©2002-2007 Karla Carter. All rights reserved. This material (including, but not limited to, Mini-lectures and Challenge Labs) may not be reproduced, displayed, modified or distributed without the express prior written permission of the copyright holder. For permission, contact Karla.