Returning a singular column from a 2D array?


Hi all,

I am trying to make a script that returns a singular column from a 2 dimensional array, which would be used as data to draw various things in Rhino. However, I always encounter an error when attempting to do this, and I cannot seem to figure out what is wrong with my code. I have my current function reproduced below:

Function ReturnColumn(ByVal col, ByVal array)

Dim colsize, i
colsize = UBound(array, 1)

ReDim vector(colsize)

For i = 0 To colsize
	vector(i) = array(i, col)  

ReturnColumn = vector

End Function

This should be a very simple function but for some reason I cannot get it to work. Any help is appreciated, thanks!

(Dale Fugier) #2

Hi @Kevin2,

Does this help?

Sub Main
  Dim chars(1, 25), row
  Dim lower, upper, c
  For row = 0 To Ubound(chars, 2)
    chars(0, row) = Chr(97 + row)
    chars(1, row) = Chr(65 + row)

  lower = ArrrayGetColumn(chars, 0)
  For Each c In lower
    Call Rhino.Print(c)

  upper = ArrrayGetColumn(chars, 1)
  For Each c In upper
    Call Rhino.Print(c)
End Sub

Function ArrrayGetColumn(ByRef arr, ByVal col)
  Dim rc(), bounds, row
  bounds = UBound(arr, 2)
  ReDim rc(bounds)
  For row = 0 To bounds
    rc(row) = arr(col, row)  
  ArrrayGetColumn = rc
End Function

– Dale