Hi there,
I've created a large macro that uses an array that is about 40 items long with three subsections each. I've recreated a smaller version of it using generic terms so that I could show it here. :) Basically I have an input box open up and it asks you what kind of pet you want. The pets I've included are Dog, Cat and Fish. When you type in the pet you want, the macro will display the kind of food you'll need to feed your pet. The macro works fine with the ok and cancel buttons, but what I can't figure out is how to make the macro display an error message when you type something other than Dog, Cat or Fish. Can anyone give me a suggestion?
Thanks!
Len
Oh and I know that my macro doesn't actually do anything with the BREED section of the array but in my REAL macro it does so I just included it to be thorough.
Here's my code:
Sub PETSHOP()
With Session
Dim PET As String
Dim BREED As String
Dim FOOD As String
Dim PETArray(0 To 2, 0 To 2) As String
'Canines
PETArray(0, 0) = "DOG"
PETArray(0, 1) = "Black Lab"
PETArray(0, 2) = "Puppy Chow"
'Felines
PETArray(1, 0) = "CAT"
PETArray(1, 1) = "Tuxedo"
PETArray(1, 2) = "Canned Tuna"
'Aquatic
PETArray(2, 0) = "FISH"
PETArray(2, 1) = "Goldfish"
PETArray(2, 2) = "Fish Flakes"
CONTINUEPET:
PET = InputBox("What kind of pet would you like?", "WHAT KIND OF PET?", "")
PET = UCase(PET)
If Len(PET) Then
GoTo CONTINUING
Else
GoTo CANCELLER
End If
CANCELLER:
Dim ISPSTOP As Integer
PETSTOP = MsgBox("Oops! You either hit CANCEL or" & _
vbCrLf & "you forgot to tell me what kind of pet you want." & _
vbCrLf & "Do you want to Try again?", vbYesNo + vbExclamation, "YOU DON'T WANT A PET?")
If PETSTOP = 7 Then
End
ElseIf PETSTOP = 6 Then
GoTo CONTINUEPET
End If
CONTINUING:
For i = 0 To 2
If StrComp(PETArray(i, 0), PET) = 0 Then
BREED = PETArray(i, 1)
FOOD = PETArray(i, 2)
Exit For
End If
Next i
.MoveCursor 23, 52
.TransmitANSI FOOD
End With
End Sub
I've created a large macro that uses an array that is about 40 items long with three subsections each. I've recreated a smaller version of it using generic terms so that I could show it here. :) Basically I have an input box open up and it asks you what kind of pet you want. The pets I've included are Dog, Cat and Fish. When you type in the pet you want, the macro will display the kind of food you'll need to feed your pet. The macro works fine with the ok and cancel buttons, but what I can't figure out is how to make the macro display an error message when you type something other than Dog, Cat or Fish. Can anyone give me a suggestion?
Thanks!
Len
Oh and I know that my macro doesn't actually do anything with the BREED section of the array but in my REAL macro it does so I just included it to be thorough.
Here's my code:
Sub PETSHOP()
With Session
Dim PET As String
Dim BREED As String
Dim FOOD As String
Dim PETArray(0 To 2, 0 To 2) As String
'Canines
PETArray(0, 0) = "DOG"
PETArray(0, 1) = "Black Lab"
PETArray(0, 2) = "Puppy Chow"
'Felines
PETArray(1, 0) = "CAT"
PETArray(1, 1) = "Tuxedo"
PETArray(1, 2) = "Canned Tuna"
'Aquatic
PETArray(2, 0) = "FISH"
PETArray(2, 1) = "Goldfish"
PETArray(2, 2) = "Fish Flakes"
CONTINUEPET:
PET = InputBox("What kind of pet would you like?", "WHAT KIND OF PET?", "")
PET = UCase(PET)
If Len(PET) Then
GoTo CONTINUING
Else
GoTo CANCELLER
End If
CANCELLER:
Dim ISPSTOP As Integer
PETSTOP = MsgBox("Oops! You either hit CANCEL or" & _
vbCrLf & "you forgot to tell me what kind of pet you want." & _
vbCrLf & "Do you want to Try again?", vbYesNo + vbExclamation, "YOU DON'T WANT A PET?")
If PETSTOP = 7 Then
End
ElseIf PETSTOP = 6 Then
GoTo CONTINUEPET
End If
CONTINUING:
For i = 0 To 2
If StrComp(PETArray(i, 0), PET) = 0 Then
BREED = PETArray(i, 1)
FOOD = PETArray(i, 2)
Exit For
End If
Next i
.MoveCursor 23, 52
.TransmitANSI FOOD
End With
End Sub