Index was outside the bounds of the array

Index was outside the bounds of the array

Anonymous
Not applicable
5,074 Views
6 Replies
Message 1 of 7

Index was outside the bounds of the array

Anonymous
Not applicable

hey everyone,

 

I have this code that reads the length of the array and also sorts the plane distance and for some reason i get an error

Index was outside the bounds of the array iLogic

 

Dim PlaneX = Double
Dim PlaneY = Double
Dim lenX = 0
Dim lenY = 0

For
Each xVar In PlaneX lenX = lenX + 1 Next For Each xVar In PLaneY lenY = lenY + 1 Next For j = 0 To lenX-2 For h = 0 To lenX-2-j If PlaneX(h) > PlaneX(h + 1) temp = PlaneX(h + 1) PlaneX(h + 1) = PlaneX(h) PlaneX(h) = temp End If Next Next For j = 0 To lenY-2 For h = 0 To lenY-2-j If PlaneY(h) > PlaneY(h + 1) temp = PlaneY(h + 1) PlaneY(h + 1) = PlaneY(h) PlaneY(h) = temp End If Next Next
0 Likes
Accepted solutions (1)
5,075 Views
6 Replies
Replies (6)
Message 2 of 7

johnsonshiue
Community Manager
Community Manager

Hi! I thought VB's array started with 1, not 0.

Many thanks!

 



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 3 of 7

Anonymous
Not applicable

hey, thanks for the reply

 

i tried changing it to 1,but i still get the same error

0 Likes
Message 4 of 7

SharkDesign
Mentor
Mentor

Think that error message means you are referencing a line in an array that doesn't exist. 

So maybe you have 5 lines in the array but one of your lenx equations is asking for 6.

That's what I understand by that error anyway. 

  Inventor Certified Professional
0 Likes
Message 5 of 7

Anonymous
Not applicable

Thanks for your reply.

 

I have tried to delete some values from the excel and still i get the same mistake.

what I have also noticed is, the components on PlaneX are getting updated and when it's switiching to PlaneY it stops and i get that error

0 Likes
Message 6 of 7

johnsonshiue
Community Manager
Community Manager

Hi! The syntax does not look like VB. Is it VB? You need to declare array like the following.

 

Dim PlaneX (10) As Double
Dim PlaneY (10) As Double

Many thanks!

 



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 7 of 7

Anonymous
Not applicable
Accepted solution

hey,

 

thanks for the idea, but i have found the mistake.

someone changed some user paramters and they where lower the what the code was suppose to read, hence the error.