VBA\Excel:Do While logic question

Associate
Joined
7 Nov 2010
Posts
87
Location
Cambridge, UK
[Solved]VBA\Excel:Do While logic question

Inside the Do While loop, if RowId-Row < 1 an error will occur.

I would have though that the "And (RowId-Row) > 0" Clause would catch this, but it doesn't and so the error happens.

This is in VBA (although the example isnt).

Does the evaluation of the clauses happen at the end of the loop? maybe im just missing something really simple :(

Code:
Bool Found = False
Int Row = 0
Int RowId = 10

Do While Found = False And (RowId - Row) > 0
	DoStuff.to(RowId-Row)
	Row = Row - 1
Loop

(in the full code,Row is a negative number used to offset RowId to find a cell based on the current selection)

Can anyone see why it's dying? Any help would be apprecianted :)

Solved: RowId - Row = 10 - (-1) = 10 + 1 = 11
Negative numbers suck :) it would always be > 0
 
Last edited:
Couldn't you nest two Do While's?

Something like:

Code:
Bool Found = False
Int Row = 0
Int RowId = 10

Do While Found = False 

       Do While (RowId - Row) > 0

	DoStuff.to(RowId-Row)
	Row = Row - 1
      
       Loop
Loop
 
Back
Top Bottom