Trimming curves in VB script component

I have a tree of curves that I’m trying to trim the ends off leaving a percentage of the curve behind in a VB component in Grasshopper, but am having some trouble. The issue I am having is that none of the curves seem to be getting modified in any way. Attached is what I am attempting, what have I messed up?

Thanks,
Sam

  Private Sub RunScript(ByVal InputCurves As DataTree(Of Object), ByVal OpenArea As Integer, ByRef A As Object) 
Dim pOpen As Double = OpenArea / 100
Dim i As Int32 = 0

Dim outTree As New DataTree(Of Curve)()

While i < InputCurves.BranchCount
  Dim j As Int32 = 0
  While j < InputCurves.Branch(i).Count
    Dim workingCurve As Curve = InputCurves.Branch(i)(j)
    '''''''''''
    Dim newDLength As Double = workingCurve.Domain.Length * (1 - pOpen)
    Dim newParam As Double = (workingCurve.Domain.Length - newDLength) / 2
    Dim oldLength As Double = workingCurve.GetLength
    
    workingCurve.Trim(newParam, newParam + newDLength)
    
    print("Old length: " & oldLength & ", new: " & workingCurve.GetLength)
    Dim Path As New GH_Path(i)
    outTree.Add(workingCurve, Path)
    
    '''''''''''
    j += 1
  End While
  A = outTree
  i += 1
End While

The Trim() method doesn’t affect the curve you call it on, it returns a new curve, which is the trimmed version of the old curve.

I’d also recommend not using while loops for iterating over collections, that’s why For and For Each were invented, but that’s not in itself a bug.

Hmm, I thought I tried that, but I must still be doing something wrong. The following gives me the error: Object reference not set to an instance of an object.

Dim newCurve As Curve = workingCurve.Trim(newParam, newParam + newDLength)

Thanks,
Sam

Are you certain workingCurve is not a null reference?