Long
Static lIndexTo As Long

Dim xEnd As Long, yEnd As Long
Dim x As Long, y As Long, y2 As Long, x2 As Long

   lIndexFrom = lIndexTo
   If (lIndexFrom = 1) Then
      lIndexTo = 0
   Else
      lIndexTo = 1
   End If
   '
   ' Get the bits in the from DIB section:
   With tSAIn
       .cbElements = 1
       .cDims = 2
       .Bounds(0).lLbound = 0
       .Bounds(0).cElements = m_tBI(lIndexFrom).bmiHeader.biHeight
       .Bounds(1).lLbound = 0
       .Bounds(1).cElements = 4 * m_tBI(lIndexFrom).bmiHeader.