1 of 1 people found this helpful
Instead of iterating through an array of an unknown length of values, I think it would be more efficient to just call AFData.RecordedValue() (or PIPoint.RecordedValue()) twice. This method takes the following relevant parameters:
time - The time at which the value is desired. Here, you would put in your discrete time.
mode - The mode is used to determine the value to return when a value does not exist at the exact time specified. The value is taken from the AFRetrievalMode enumeration. This is where the two calls will differ. One call you would use AtOrBefore, and the next you would use AtOrAfter.
Then the rest of the logic would be in your code to validate that the returned value's timestamp falls within your overall time range, as well as to determine which returned value from the two calls is closest to your discrete timestamp. Additional logic could be added after the first call to RecordedValue() if an exact match is found so that the second call does not need to be made unnecessarily.
That's brilliant! Thanks for the tip. Will give that a try and let you know how it goes. Will post my code as well