Hi,
This is more of a VBA rather than a Solidworks question. I'm trying to compare the first item in an array with the second item in the array as follows:
i = 0 For Each i In LengthsArr If LengthsArr(i) > LengthsArr(i + 1) Then llong = llong + QuanArr(i) Else Short = Short + QuanArr(i) End If Next i
It doesn't seem to work, line 4 throws up an error:
"Run-time error: 9: Subscript out of range"
Anybody know why I am getting this?
The "for each" construction attempts to assign the content of the array to the variable for each element of the array.
That means if your array contains (23, 56, 32, 54)
then the first time through the loop "i" will be 23. Next time it's 56.
You need to use
for i = 0 to (ubound(LengthsArr)-1)
Then i will be 0,1,2, etc.