*

Code for Aggregation Mini-Lecture: Day 1

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 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
            Select Case intTypeCare
                Case 0 'Feed
                    Select Case LCase(strPetType)
                        Case Is = "cat"
                            MsgBox "Cat will need some chicken and some water", OK, "Pet Care"
                        Case Is = "dog"
                            MsgBox "Dog will need something interesting off the counter and some water", OK, "Pet Care"
                    End Select
                Case 1 'Clean
                    Select Case LCase(strPetType)
                        Case Is = "cat"
                            MsgBox "Cat will lick itself clean", OK, "Pet Care"
                        Case Is = "dog"
                            MsgBox "Dog will need a bath", OK, "Pet Care"
                    End Select
                Case 2 'Exercise
                    Select Case LCase(strPetType)
                        Case Is = "cat"
                            MsgBox "Cat will need to play with bed mice or a catnip toy", OK, "Pet Care"
                        Case Is = "dog"
                            MsgBox "Dog will need to chase a ball and run", OK, "Pet Care"
                    End Select
                Case 3 'Love
                    Select Case LCase(strPetType)
                        Case Is = "cat"
                            MsgBox "Cat will need to be petted a lot and made a fuss over", OK, "Pet Care"
                        Case Is = "dog"
                            MsgBox "Dog will need to be petted a lot and made a fuss over", OK, "Pet Care"
                    End Select
            End Select
            'reset data for next use
            lstPetType.ListIndex = -1
            optPetCare(intTypeCare) = False
    End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
    'release the form object
    Set frmPetCare = Nothing
End Sub
Private Function ValidatedInput() As Boolean
    'this procedure will need to be customized for whatever front-end
    Dim blnValidated As Boolean
    
    Dim PetCare 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 PetCare In optPetCare
        'if so, leave the validated flag at true and exit
        If PetCare.Value = True Then
            'release the optionbutton object
            Set PetCare = Nothing
            GoTo ExitHere
        End If
    Next PetCare
    '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 PetCare = Nothing
    GoTo ExitHere
ExitHere:
    'single out
    ValidatedInput = blnValidated
End Function

Private Sub optPetCare_Click(Index As Integer)
    intTypeCare = Index
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.