ICI logo


Intersystem Concepts, Inc.



VB6 Error 10 Fix

Your project runs fine in the IDE, so you compile it into an EXE, run it, and get the following message:

The message occurs upon an attempt to ReDim an array.

While this may have several possible causes, one we encountered was due to improper use of an array element inside a nested With block.

The following code snippet from a routine that employs the TextOut API to display rotated text illustrates the situation:

  Dim Log_Font As logfonttype
  With arr(index)
    With Log_Font
      .lfEscapement = .frotation         $$ HERE'S THE TROUBLE
      .lfHeight = -24 
      .lfFaceName = Me.FontName & vbNullChar
      .lfWeight = 400
    End With
    lfontnew& = CreateFontIndirect(Log_Font)
    lfontold& = SelectObject(Me.hDC, lfontnew&)
    If TextOut&(Me.hDC, 0, 0, .stext, Len(.stext)) = 0 Then
      Debug.Print "TextOut Error"
    End If
    Call SelectObject(Me.hDC, lfontold&)
    Call DeleteObject(lfontnew&)
  End With
The fourth line of code above should instead read:
      .lfEscapement = arr(index).frotation       
but due to the nested With blocks, the problem is easy to miss. As an .EXE VB6 ties the array element .frotation to the TextOut object, and this results in confusion (Error 10) later when the array is redimensioned. Change the example as shown and the problem goes away.
Other VB tips