CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2003
    Posts
    74

    Smile looping past index limit

    Hey Kids,

    THis is a little strange, but probably simple. I am doing a standard loop, but it keeps going past the limit...

    Dim FlowRaster(1 To 12) As IRaster
    For i = 1 To 12
    do some **** here
    Next i

    i keeps trying to process a 13th entry???? Any ideas?
    The reason I set the lower bound index to 1 instead of the usual 0, is just for easier interpretation, these are months.

    Thanks

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    You sure you do not change value of "i" inside the for next?
    To be sure:
    before next statement, write:
    debug.print "i= " & i
    and look at values.
    it should start with 1 and end with 12
    (of course, after the next statement -exiting the next - it should be = 13)
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Apr 2003
    Posts
    74

    Unhappy index loop error

    Hey Cimp

    no I don't change anything, and I have checked, the value definetly changes to 13 inside the loop. here is all my code


    Dim FlowRaster(1 To 12) As IRaster
    For i = 1 To 12
    Set FlowRaster(i) = SWFFunctions.SetFlows(pRaster3, "Flow_Rcl", i, outputpath)
    Next i


    Just a little strange, huh?????

  4. #4
    Join Date
    Oct 2002
    Location
    Arkansas, USA
    Posts
    189
    no I don't change anything, and I have checked, the value definetly changes to 13 inside the loop.
    I assume because you say this, that after the loop completes, the value of i is 14?

  5. #5
    Join Date
    Jan 2002
    Location
    Quebec/Canada
    Posts
    124
    How many times to you loop really ? The only reason i see it may be doing this is that i is passed by reference to SWFFunctions.SetFlows and SetFlows increment your value of i and return the new value.

    if you can change the definition of SetFlow be sure to set ByVal for the i parameter.

    If that cannot be done, use another var to pass the i value to SetFlows.

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    Set FlowRaster(i) = SWFFunctions.SetFlows(pRaster3, "Flow_Rcl", i, outputpath)

    you sure i is not changed in setFlows (Heulsay probably got the matter...) ?
    you could code also
    Code:
    Dim FlowRaster(1 To 12) As IRaster
    dim tmpCounter as integer
    For i = 1 To 12
       tmpCounter=i
       Set FlowRaster(i) = SWFFunctions.SetFlows(pRaster3, "Flow_Rcl", tmpCounter, outputpath)
    Next i
    if you cannot change the byref of the method...
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  7. #7
    Join Date
    Apr 2003
    Posts
    74

    Thumbs up Cimp wins

    Cimper,
    You are the man, I foolishly was using i in another loop in the called function, so that was superseding my passed i. I must expand my alphabet.
    Thanks

  8. #8
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Red face Heulsay deserve some credit, too...

    ...LOL...It was not a race, but in any case Heulsay said it as first (byref variable, is not it?)
    ("give Caesar what is of Caesar"... )
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured