OutOfBoundError when scrolling the listbox

Hello all,

Can somebody help me with the OutOfBoundException error I receive when scrolling through the listbox list.

I created the next code, which does give the background of a row a certain color when a certain value is found in the tag of a cell:

  If val(ShowDetails.DisViewer.CellTag(row,1)) < 3 then
    DisColor1=white
  elseif  val(ShowDetails.DisViewer.CellTag(row,1)) >= 3 and  val(ShowDetails.DisViewer.CellTag(row,1)) < 4 then
    DisColor1 = LYellow
  elseif  val(ShowDetails.DisViewer.CellTag(row,1)) >= 4 and  val(ShowDetails.DisViewer.CellTag(row,1))<5 then
    DisColor1 = dGreen
  elseif val(ShowDetails.DisViewer.CellTag(row,1))  >= 5 and  val(ShowDetails.DisViewer.CellTag(row,1))<6 then
    DisColor1 = Yellow
  elseif  val(ShowDetails.DisViewer.CellTag(row,1))  >= 6 and  val(ShowDetails.DisViewer.CellTag(row,1)) <7 then
    DisColor1 = Orange
  elseif  val(ShowDetails.DisViewer.CellTag(row,1)) >= 7 and  val(ShowDetails.DisViewer.CellTag(row,1))<8 then
    DisColor1 = Red
  elseif  val(ShowDetails.DisViewer.CellTag(row,1)) >= 8 then
    DisColor1 = Purple
  End If

  g.foreColor=Discolor1
  g.FillRect 0,0,g.width,g.height

As long as I do not touch the listbox for scrolling nothing goes wrong and it is update correctly every three minutes, because it is a realtime application, but as soon as I scroll I get the OutOfBoundEception error.

I checked how many rows I have with listcount, but that is just as much as should be displayed. When I open the OutOfBoundEception error in the debugger it has errorcode 0

I am strugling now for longer time to get rid of this error, but it keeps coming back. I hope someone does know a solution for this

Rob

Just set a

[code]If Row > -1 And Row < Me.ListCount Then

YOUR CODE

End If[/code]

around your Code. :slight_smile:

If Row > -1 And Row < Me.ListCount And column < Me. ColumnCount Then ... End

Thanks Sascha and Eli for your replies. I added teh line Sascha proposed and it works. No OutOfBound error anymore. Thanks to both of you for the solution.

Rob