title: VB6: Runtime Error '13': Type Mismatch when setting and int with an int
body: <p>I'm not new to VB6 programming, but I'm not a master at it either. Hopefully someone can help me out with a question that I have concerning a Type Mismatch error that I'm receiving from trying to set an int variable with a int returned from a function.</p>
  
  <p>The integer that I'm trying to set is defined as:</p>
  
  <pre><code>Global AICROSSDOCKStatus As Integer
  </code></pre>
  
  <p>Now when I try to make this call I get the Runtime Error 13</p>
  
  <pre><code>AICROSSDOCKStatus = ProcessQuery(iocode, pb, AICROSSDOCBOLFN, "")
  </code></pre>
  
  <p>I've stepped through debugging the program line for line. The ProcessQuery function gets and returns the expected integer, but when the assignment is to be made to the AICROSSDOCKStatus it fails.</p>
  
  <p>On a side note, I've also tried doing a CInt() to the ProcessQuery with the same result.</p>
  
  <p>Does anyone have any suggestions for what I may be able to try?</p>
  
  <p>Edit:
  Here is the definition of ProcessQuery</p>
  
  <pre><code>Function ProcessQuery(icode As Integer, pb As ADODB.Recordset, TableName As String, sql$) As Integer
  </code></pre>
  
  <p>Edit 2:  I couldn't tell you why this was done in this manner. I inherited the code base. Yikes...</p>
  
  <pre><code>
  Function ProcessQuery(icode As Integer, pb As ADODB.Recordset, TableName As String, sql$) As Integer
      ProcessQuery = ProcessQuery1(icode, pb, TableName, sql$)
  End Function
  </code></pre>
  
  <pre><code>
  Function ProcessQuery1(icode As Integer, pb As ADODB.Recordset, TableName As String, sql$) As Integer
  ''THIS IS THE ORIGINAL SQL CALL ROUTINE!
  Dim STATUS As Integer
  On Error GoTo ProcessSQLError
  
  STATUS = 0
  Select Case icode
     Case BCLOSE
          If pb.State  0 Then
              pb.Close
          End If
          Set pb = Nothing
          STATUS = 3
      Case BOPEN
          STATUS = 9
          Set pb = New ADODB.Recordset
      Case BOPENRO
          STATUS = 9
          Set pb = New ADODB.Recordset
      Case BGETEQUAL, BGETEQUAL + S_NOWAIT_LOCK, BGETGREATEROREQUAL, BGETGREATEROREQUAL + S_NOWAIT_LOCK
          If pb.State  0 Then
              pb.Close
              ''Set pb = Nothing
              ''Set pb = New ADODB.Recordset
          End If
          pb.Open sql$, MISCO_SQL_DB, adOpenDynamic, adLockOptimistic
          If Not pb.EOF Then
              pb.MoveFirst
          Else
              STATUS = 9
          End If
      Case BGET_LE, BGET_LE + S_NOWAIT_LOCK
          If pb.State  0 Then
              pb.Close
          End If
          pb.Open sql$, MISCO_SQL_DB, adOpenDynamic, adLockOptimistic
          If Not pb.BOF Then
              pb.MoveLast
  
          Else
              STATUS = 9
          End If
      Case BGETFIRST, BGETFIRST + S_NOWAIT_LOCK
          If pb.State  0 Then pb.Close
          sql = "select * from " + TableName
          If InStr(1, gblOrderBy, "ORDER BY") > 0 Then
              sql = sql + gblOrderBy
          Else
              sql = sql + " ORDER BY " + gblOrderBy
          End If
  
          gblOrderBy = ""
          pb.Open sql$, MISCO_SQL_DB, adOpenDynamic, adLockOptimistic
          If Not pb.EOF Then
                                                          pb.MoveFirst
          End If
      Case BGETLAST, BGETLAST + S_NOWAIT_LOCK
          If pb.State  0 Then
              pb.Close
          End If
          sql = "select * from " + TableName
          If InStr(1, gblOrderBy, "ORDER BY") > 0 Then
              sql = sql + gblOrderBy
          Else
              sql = sql + " ORDER BY " + gblOrderBy
          End If
          gblOrderBy = ""
          pb.Open sql$, MISCO_SQL_DB, adOpenDynamic, adLockOptimistic
          If Not pb.EOF Then
              pb.MoveFirst
              pb.MoveLast
          End If
      Case BGETNEXT, BGETNEXT + S_NOWAIT_LOCK:            pb.MoveNext
      Case BGETPREVIOUS, BGETPREVIOUS + S_NOWAIT_LOCK:    pb.MovePrevious
      Case B_UNLOCK
          ''need to add code here
      Case BINSERT
          If pb.State = 0 Then
              pb.Open TableName, MISCO_SQL_DB, adOpenDynamic, adLockOptimistic
          End If
      Case BDELETE
          STATUS = 8
          pb.Delete
      Case Else
          STATUS = 1
          MsgBox "STOP: UNDEFINDED PROCEDURE" + Str$(icode)
  End Select
  If STATUS = 0 Then
      If pb.EOF Or pb.BOF Then STATUS = 9
  End If
  
  ProcessQuery1 = STATUS
  Exit Function
  
  ProcessSQLError:
      MsgBox TableName + ": " + Error(Err), vbCritical, "Error "
      ProcessQuery1 = 9
  
  End Function
  </code></pre>