View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
joeu2004[_2_] joeu2004[_2_] is offline
external usenet poster
 
Posts: 829
Default Easy answers for anyone

"m5u4r3p2h1y" wrote:
in message ...
was hoping if anyone code tell me why the following code
only loops once.

[....]
Dim i, count As Integer

[....]
For i = 0 To i = 9


The For statement should be:

For i = 0 to 9

As you wrote, it is parsed as:

For i = 0 to (i = 9)

"i = 9" returns True (-1) or False (0). Since i=0 initially, "i = 9" is
False (0). So your For statement is effectively:

For i = 0 to 0

which will indeed loop only once.

By the way, you Dim statement should probably be at least:

Dim i As Integer, count As Integer

As you wrote it, i is Variant. I suspect that was not your intent.

Also, there is little point in using Integer type, unless you have very huge
arrays. You should use Long to be flexible. There is no performance cost
in modern computers.