Public Function CalcAPValue(targetDate As Date) As Double ' edited Dim cumulativeAPValue As Double = 0 Dim symbol As String Dim units As Double Dim posValue As Double For Each myRow As DataRow In myDataSet.Tables("AcquiredPositionsTbl").Rows symbol = myRow("Symbol").ToString().Trim units = myRow("Units") If symbol <> "CAccount" Then posValue = units * CalcMTM(symbol, targetDate) cumulativeAPValue = cumulativeAPValue + posValue myRow("Value") = posValue End If Next Return cumulativeAPValue End Function Public Function CalcAPMargin(targetDate As Date) As Double Dim cumulativeAPMValue As Double = 0 Dim symbol As String Dim units As Double Dim posValue As Double For Each myRow As DataRow In myDataSet.Tables("AcquiredPositionsTbl").Rows symbol = myRow("Symbol").ToString().Trim units = myRow("Units") If symbol <> "CAccount" And units < 0 Then posValue = units * CalcMTM(symbol, targetDate) cumulativeAPMValue = cumulativeAPMValue + posValue End If Next Return cumulativeAPMValue End Function