Why the minus 1?

  • Thread starter Thread starter TeeSee
  • Start date Start date
T

TeeSee

I very often see code for a loop, lets say loop thru controls, that
goes something like ....

for x = 0 to control.count -1
for x = 1 to control.count -1

Why the Minus 1 ??
 
I very often see code for a loop, lets say loop thru controls, that
goes something like ....

for x = 0 to control.count -1
for x = 1 to control.count -1

Why the Minus 1 ??

Because many of these collections are zero based. If there are three controls
on a form, they're numbered 0, 1, and 2, but the control.count is 3, so if you
looped to control.count you'ld get an error - subscript out of range.
 
Back
Top