Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

For next doesn't loop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
joshuafandango@dsl.pipex.com - 29 May 2008 17:08 GMT
Hi guys,

At the end of a long, hard day slaving over a keyboard I'm befuddled
by something that should be easy (or so I thought).

For some reason the for next in the following doesn't loop!?!

Sub Test()
Dim i, BuildChkSum, ChkSum As Integer
 For i = 0 To i = 9
   BuildChkSum = Mid(1234567899, i + 1, 1) * 10 - i
   ChkSum = ChkSum + BuildChkSum
   i = i + 1
 Next i
Debug.Print i
Debug.Print ChkSum
End Sub

i comes out as 2 in the debug statement when I hoped it would be 9 -
seeing as it's not looping shouldn't it be 1?

Any ideas?

Cheers,
JF
Sam Wilson - 29 May 2008 17:26 GMT
You don't need i = i + 1 in there, it increments i for you.

Sam

> Hi guys,
>
[quoted text clipped - 21 lines]
> Cheers,
> JF
NateBuckley - 29 May 2008 17:27 GMT
Dim i As Long
   For i = 0 To 9
        'Code goes here
   Next i

> Hi guys,
>
[quoted text clipped - 21 lines]
> Cheers,
> JF
Tim Zych - 29 May 2008 17:27 GMT
For i = 0 to 9
Take out the i=i+1 part. The For..next loop increments i

Signature

Tim Zych
www.higherdata.com
Compare data in workbooks and find differences with Workbook Compare
A free, powerful, flexible Excel utility

> Hi guys,
>
[quoted text clipped - 21 lines]
> Cheers,
> JF
Sam Wilson - 29 May 2008 17:28 GMT
And it should be "For i = 0 to 9" not "For i=0 to i=9"

Sam

> Hi guys,
>
[quoted text clipped - 21 lines]
> Cheers,
> JF
Joel - 29 May 2008 17:28 GMT
You should increment a loop count yourself like i.  Let the for do it for you

 For i = 0 to 9 step 2
   BuildChkSum = Mid(1234567899, i + 1, 1) * 10 - i
   ChkSum = ChkSum + BuildChkSum
 Next i

> Hi guys,
>
[quoted text clipped - 21 lines]
> Cheers,
> JF
joshuafandango@dsl.pipex.com - 30 May 2008 10:03 GMT
Thanks everyone, am I a dumb-a.s or what? :)

> You should increment a loop count yourself like i.  Let the for do it for you
>
[quoted text clipped - 31 lines]
>
> - Show quoted text -
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.