Can anyone offer an explanation please? (Code below).
I have a VB2005 express program that reads through a dataset (approx 100 records) looking at items 7 and 8.
If item 7 has a particular value ("R"), then I wish to delete the record.
A filter 'srsshow' is turned on to activate the feature.
When the filter is activated, this always returns the error - 'There is no row at position 9'.
However if the line with the remove statement is disabled, the loop runs right through the file without a problem, indicating that this is the line that is causing trouble. Also, the last 'debug.writeline ' before the error message returns "line 8".
What is the problem?
Why does the 'debug.writeline' not show "9" as it is executed before the line causing the error?
Many thanks.
Phil
Expand|Select|Wrap|Line Numbers
- For x = 0 To mdrows - 1
- For y = 7 To 8
- dataread = dt.Rows(x).Item(y)
- 'discard records not required
- If y = 7 And srshow = 0 And dataread = "R" Then skiprec = 1
- Next y
- Debug.WriteLine("line " & x )
- If skiprec = 1 Then dt.Rows.Remove(dt.Rows(x))
- skiprec = 0
- y = 7
- Next x