AnsweredAssumed Answered

looking to optimize VB.net code

Question asked by Koerkel on May 31, 2019
Latest reply on May 31, 2019 by rdavin

I need to pull 4 different data values for a list of elements.  The code I have works but it requires 4 different "For Each" loops.  I'm trying to figure out a method to run this code in a single loop but each attempt fails.  Can someone please suggest a better method?
 

Here is my code:

 

' grab the kWh Delivered data totaled for the time interval
Dim kwhdelresults As IEnumerable(Of IDictionary(Of Data.AFSummaryTypes, Asset.AFValue)) _
      = taggroupkwhdel.Summary(readtimes, Data.AFSummaryTypes.Total, Data.AFCalculationBasis.EventWeighted, _
    Data.AFTimestampCalculation.MostRecentTime, pageconfig)

For Each p1Results As IDictionary(Of Data.AFSummaryTypes, Asset.AFValue) In kwhdelresults
      kwhdelreads = p1Results(Data.AFSummaryTypes.Total)
      mTLM = Mid(kwhdelreads.PIPoint.Name, 1, 12)
      xloop = kwhdelreads.Value
Next

' grab the kWh Received data totaled for the time interval
Dim kwhrecresults As IEnumerable(Of IDictionary(Of Data.AFSummaryTypes, Asset.AFValue)) _
      = taggroupkwhrec.Summary(readtimes, Data.AFSummaryTypes.Total, Data.AFCalculationBasis.EventWeighted, _
      Data.AFTimestampCalculation.MostRecentTime, pageconfig)

For Each p2Results As IDictionary(Of Data.AFSummaryTypes, Asset.AFValue) In kwhrecresults
      kwhrecreads = p2Results(Data.AFSummaryTypes.Total)
      mTLM = Mid(kwhrecreads.PIPoint.Name, 1, 12)
      xloop = kwhrecreads.Value
Next

' grab the kVAR Delivered data totaled for the time interval
Dim vardelresults As IEnumerable(Of IDictionary(Of Data.AFSummaryTypes, Asset.AFValue)) _
      = taggroupkvardel.Summary(readtimes, Data.AFSummaryTypes.Total, Data.AFCalculationBasis.EventWeighted, _
      Data.AFTimestampCalculation.MostRecentTime, pageconfig)

For Each p3Results As IDictionary(Of Data.AFSummaryTypes, Asset.AFValue) In vardelresults
      vardelreads = p3Results(Data.AFSummaryTypes.Total)
      mTLM = Mid(vardelreads.PIPoint.Name, 1, 12)
      xloop = vardelreads.Value
Next

' grab the kVAR Received data totaled for the time interval
Dim varrecresults As IEnumerable(Of IDictionary(Of Data.AFSummaryTypes, Asset.AFValue)) _
      = taggroupkvarrec.Summary(readtimes, Data.AFSummaryTypes.Total, Data.AFCalculationBasis.EventWeighted, _
      Data.AFTimestampCalculation.MostRecentTime, pageconfig)

For Each p4Results As IDictionary(Of Data.AFSummaryTypes, Asset.AFValue) In varrecresults
      varrecreads = p4Results(Data.AFSummaryTypes.Total)
      mTLM = Mid(varrecreads.PIPoint.Name, 1, 12)
      xloop = varrecreads.Value
Next

Outcomes