迈克尔,你的函数有缺陷,因为它没有创建适当大小的新数组,也没有正确填充它。
试试这个:
- Function ConvertPoints(ByRef PointsArray() As Double) As Variant
- 'function creates a new array to hold three dimensional points and converts 2D points into 3D with z=0
- Dim PreviousBound As Integer, NewBound As Integer, NewPoints() As Variant
- PreviousBound = (UBound(PointsArray) + 1) / 2
- NewBound = (PreviousBound * 3) - 1
- ReDim NewPoints(NewBound)
- Dim i As Integer
- Dim j As Integer
- For i = 0 To UBound(PointsArray) Step 2
- NewPoints(j) = PointsArray(i)
- NewPoints(j + 1) = PointsArray(i + 1)
- NewPoints(j + 2) = 0#
- j = j + 3
- Next i
- ConvertPoints = NewPoints
- End Function
|