 |
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()
If ValidatedInput Then
Select Case intTypeCare
Case 0
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
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
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
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
lstPetType.ListIndex = -1
optPetCare(intTypeCare) = False
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set frmPetCare = Nothing
End Sub
Private Function ValidatedInput() As Boolean
Dim blnValidated As Boolean
Dim PetCare As OptionButton
If lstPetType.ListIndex < 0 Then
MsgBox _
"You must select a pet before continuing", _
OK, _
MessageTitle
lstPetType.SetFocus
blnValidated = False
GoTo ExitHere
Else
strPetType = lstPetType.Text
blnValidated = True
End If
For Each PetCare In optPetCare
If PetCare.Value = True Then
Set PetCare = Nothing
GoTo ExitHere
End If
Next PetCare
MsgBox _
"You must select a type of care for your " _
& strPetType & " before continuing", _
OK, _
MessageTitle
blnValidated = False
Set PetCare = Nothing
GoTo ExitHere
ExitHere:
ValidatedInput = blnValidated
End Function
Private Sub optPetCare_Click(Index As Integer)
intTypeCare = Index
End Sub

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.
|