I have a flexgrid where the first column holds numbers.

The code below shows tooltiptext based on these numbers when you move the mouse over them.

With the following code, how can I stop getting integer overflow errors when the mouse moves over the flexgrid where there is no valid line ? What I mean is the maximum number of rows which can be displayed at once is 15, but if only the first 2 or 3 are populated, this leaves a 'grey area' and the code below can't handle that, and if the mouse moves in this 'grey area' I get integer overflow errors at the line marked with an arrow.

Can anyone help me out ? I need to sort this quick, so any input would be very much appreciated.

Thanks in advance.


VB Code:
  1. Private Sub flxDetails_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  2.  
  3.     Static SelectedRow As Long
  4.     Dim rowNum As Long
  5.     Dim colNum As Long
  6.     Dim z As Integer
  7.     Dim BrnName As String * 30
  8.    
  9.        
  10.     If ReadyToProceed Then
  11.         With flxDetails
  12.             rowNum = y \ .RowHeight(1) + .TopRow + 1
  13.             colNum = x \ .ColWidth(1) + .LeftCol + 1
  14.        
  15.        
  16.                 If rowNum <> SelectedRow And colNum = 1 Then
  17.                     SelectedRow = rowNum
  18.                     For z = 0 To 999
  19.       -->                 If .TextMatrix(rowNum - 2, 0) = tmpBRN(z) Then
  20.                             BrnName = tmpBrnName(z)
  21.                             x = 999
  22.                         End If
  23.                     Next z
  24.                    
  25.                     .ToolTipText = Trim(BrnName)
  26.                    
  27.                     If .TextMatrix(rowNum - 2, 0) = "050" Then
  28.                         .ToolTipText = "Nantgarw Warehouse"
  29.                         Exit Sub
  30.                     End If
  31.                
  32.                 End If
  33.         End With
  34.     End If
  35.  
  36. End Sub