Imagine a range of numbers from -133 to +71.
I want to find the first and last numbers in the range that divide by 20: in this case it would be -120 and +60.
I can write a For loop that tests each value and stores the required values:
Dim resultFirst, resultLast As Integer Dim FirstFound As Boolean = False For a As Integer = -133 To 71 If a Mod 20 = 0 Then If FirstFound = False Then resultFirst = a FirstFound = True End If resultLast = a End If Next
but I suspect there is a simpler formula.