Run-time Error '13'

bama58
bama58 used Ask the Experts™
on
Why am I getting this error code (Run-time Error '13'Type Mismatch)?  The code is triggered in the Private Function GetPicture.  I am trying to get my GUI to load jpeg pictures based on the users section of "swing" and "alignment".  Once the users make a selection they press the cmddisplay and text appears in the text box and a picture is supposed to appear in the picture box.

Private Function GetSwing() As String
   Dim index As Long
   For index = 0 To 2
   If Swing(index).Value = True Then Exit For
      Next
   If index = 3 Then
       MsgBox "You must select a swing!", vbCritical
Exit Function
 End If
   Select Case index
     Case 0
      GetSwing = "Ball starts to the right of target"
     Case 1
      GetSwing = "Ball goes directly toward the target"
     Case 2
      GetSwing = "Ball starts to the left of target"
           
  End Select
           
End Function

Private Function GetAlign() As String
   
    Dim index As Long
     For index = 0 To 4
      If Align(index).Value = True Then Exit For
     Next
      If index = 5 Then
      MsgBox "You must select an alignment!", vbCritical
 Exit Function
 End If
  Select Case index
  Case 0
   GetAlign = " and curves to the right of the target (a fade)"
  Case 1
   GetAlign = " and curves a lot to the right of the target (a slice)"
  Case 2
   GetAlign = " and stays on the swing path line (straight)"
  Case 3
   GetAlign = " and curves to the left of target (a draw)"
  Case 4
   GetAlign = " and curves a lot to the left of target (a hook)"
     End Select
   
End Function

Private Sub cmdExit_Click()
    Unload Me
End Sub

Private Sub cmdDisplay_Click()
    results.Text = GetSwing() & GetAlign()
    Picture1.Picture = LoadPicture(GetPicture)
End Sub


Private Function GetPicture() As String
    Dim index As Long
        For index = 0 To 15
  If Swing(index).Value & Align(index).Value = True Then Exit For
        Next
       
         If Swing(0) & Align(0) = True Then
            GetPicture = "e:\cases-jpg\case 0-0.jpg"
             End If
        If Swing(0) & Align(1) = True Then
            GetPicture = "e:\cases-jpg\case 0-1.jpg"
                 End If
        If Swing(0) & Align(2) = True Then
            GetPicture = "e:\cases-jpg\case 0-2.jpg"
                 End If
        If Swing(0) & Align(3) = True Then
            GetPicture = "e:\cases-jpg\case 0-3.jpg"
                 End If
        If Swing(0) & Align(4) = True Then
            GetPicture = "e:\cases-jpg\case 0-4.jpg"
                 End If
        If Swing(1) & Align(0) = True Then
            GetPicture = "e:\cases-jpg\case 1-0.jpg"
                 End If
        If Swing(1) & Align(1) = True Then
            GetPicture = "e:\cases-jpg\case 1-1.jpg"
                 End If
        If Swing(1) & Align(2) = True Then
            GetPicture = "e:\cases-jpg\case 0-2.jpg"
                 End If
        If Swing(1) & Align(3) = True Then
            GetPicture = "e:\cases-jpg\case 1-3.jpg"
                 End If
        If Swing(1) & Align(4) = True Then
            GetPicture = "e:\cases-jpg\case 1-4.jpg"
                 End If
        If Swing(2) & Align(0) = True Then
            GetPicture = "e:\cases-jpg\case2-0.jpg"
                 End If
        If Swing(2) & Align(1) = True Then
            GetPicture = "e:\cases-jpg\case 2-1.jpg"
                 End If
        If Swing(2) & Align(2) = True Then
            GetPicture = "e:\cases-jpg\case 2-2.jpg"
                 End If
        If Swing(2) & Align(3) = True Then
            GetPicture = "e:\cases-jpg\case 2-3.jpg"
                 End If
        If Swing(2) & Align(4) = True Then
            GetPicture = "e:\cases-jpg\case 2-4.jpg"
                 End If
       End Function
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
Do you know on which line of code the error happens?

Check out this:
' Picture1.Picture = LoadPicture(GetPicture)
SET Picture1.Picture = LoadPicture(GetPicture)

CHeers

Commented:
Hi bama58

This might sound silly, but are you sure that the paths are right.  For example "e:\cases-jpg\case 2-4.jpg", because some machines can be setup to be case sensitive.
I see a problem with this code:

If Swing(index).Value & Align(index).Value = True Then Exit For


You are trying to concatenate boolean values like they were strings.  Change to

If Swing(index).Value AND Align(index).Value = True Then Exit For

Author

Commented:
Thanks everyone for your help, IT is now Working properly.  Problem was that I was using "&" instead of "AND" in code.  Visual Basic must not recognize the Boolean in a string???  Anyway when I changed the codes to this the program worked.  

Also, I didn't need this portion of the code
      (Dim index As Long
: :   For index = 0 To 15
: :   If Swing(index).Value & Align(index).Value = True Then Exit For
: :    Next)

In fact the code wouldn't work properly until I deleted it.


[code]
               If Swing(0) AND Align(0) = True Then
: :            GetPicture = "e:\cases-jpg\case 0-0.jpg"
: :             End If

[code]

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial