Problem with For...Next loop

J

Jey

All of my For... Next loops are giving me problems:

For intI = 3 To 10000
If (blah blah blah) = (blah blah bla) Then Exit For
(do some other stuff)
Next intI

As such it works fine, no problems. However, I realized that I need it to
loop more than 10000 times, so I go in and change it to 1000000... and now it
ignores the For statement, leaves intI = 0 (the value it was set to when
initially declared), and just runs through the code as if the For...Next loop
doesn't even exist. If I re-set to 10000, it all works fine again! I'm not
changing anything else in the code, just adding or taking away 0s. I can
change the value to 1000, 100, or 10, and it still works fine. 100000 or
higher, nothing.

I checked another loop elsewhere in the code, with the same result. If I
edit (upwards) the value it loops to, it ignores the loop and fails to reset
intI.

I'm utterly baffled. Can anyone polease tell me what is going on here?

Jey
 
V

vseale

Integer has a maximum value of 32,767. You need to use Long. It has a
maximum value of 2,147,483,647.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top