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

I should have included some variable declarations:

Dim taggroupkwhdel As PI.PIPointList = New PI.PIPointList

Dim taggroupkwhrec As PI.PIPointList = New PI.PIPointList

Dim taggroupkvardel As PI.PIPointList = New PI.PIPointList

Dim taggroupkvarrec As PI.PIPointList = New PI.PIPointList