Grasshopper

algorithmic modeling for Rhino

VB.Net - Same Code - One File Works, Other Retuns an Index (Line: 0) Error

I modified my original code (based on trigonometry) to include RhinoCommon scripting to clean and shorten my code. I now get the error:

error: index must be less than the size of the collection (line: 0 )

The strange thing is that when I originally scripted the working (inelegant) code, it gave the same error at first, and "magically" corrected itself without any code changes. I just exited the scripting window and viola! It worked as it should (and I was too happy to care why this happened).

I know the error lies in the code beginning with:

    For i As Int32 = 0 To n - 1
      For j As Int32 = 0 To n - 1
        MidPt = IntPts(i, j)
        TopPt = IntPts(i, j + 1)
        BtmPt = IntPts(i + 1, j)

If you delete that section the first section executes and outputs the same exact information as the working file. It's the exact same code working in one, and not in the other!!! I don't get it!

Views: 538

Attachments:

Replies to This Discussion

Hi Dave,

on my machine it throws an error on line 247, which is beyond the bottom of the script, so something is definitely off here. However I believe there's a bug in your code as well.

In your nested loop, i and j both go all the way to n-1, which is the highest possible index in those arrays. However when you access the arrays, you use j+1 and i+1, which, on the final iteration, will go beyond the array bounds.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

First, thank you so much for the reply! I am pulling my hair on this one.

In reference to the other part. I'm not so sure about that....

Use beta=72, n=4 as an example.

Dim IntPts(n,n) As Point3d creates an nxn matrix (0 to 4),(0 to 4), OR 5X5

The loop only goes to (i-1),(j-1), (3,3)

i+1,j+1 = 4 which is within the range of IntPts.

Even so, why would one code work and not the other though? Although the initial code is slightly modified, it sends the same information to the second part which is identical code. Am I still missing something?

Oh yes, I forgot VB declares arrays differently from C#. VB uses upper bounds, C# uses lengths. Digging deeper...

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service