Accessing previous row in Asynch Script Component

I have a series of records that are timestamped and ordered by time ascending. i.e.

Time TimeToNext
02/07/2007 11:38:22 0:00:21 <--- Need to calculate these
02/07/2007 11:38:43 0:00:22 <--- Need to calculate these
02/07/2007 11:39:06 0:00:00 <--- Need to calculate these
02/07/2007 11:39:06 0:00:36 <--- Need to calculate these
02/07/2007 11:39:42 0:00:28 <--- Need to calculate these
02/07/2007 11:40:10 0:00:26 <--- Need to calculate these
02/07/2007 11:40:36 Last Record <--- Need to calculate these

I need to calculate the difference in time between each of these records.  The flow should go like this (psuedo):

1. Read FirstRecord

2. Read SecondRecord

3. Set FirstRecord.TimeToNext =  SecondRecord.Time - FirstRecord.Time

4. Output FirstRecord

Repeat for all rows in buffer (i.e. SecondRecord.TimeToNext = ThirdRecord.Time - SecondRecord.Time)

I am sure there is an easy way to do this with a script component, but I haven't been able to figure it out, and my head hurts from smashing it against my desk. 

Any suggestions would be greatly appreciated.



Answer this question

Accessing previous row in Asynch Script Component

  • Jon W.

    Does SecondRecord become FirstRecord when comparing against ThirdRecord


  • Scott H

    Thinking in terms of pseudo-code:

    dim counter = 1
    public overrides sub input0_processinputrow(.....)
    dim column1 as datetime
    if counter == 1 then 'set variable equal to first row's time value
    column1 = row.column1.value
    else ' since we are not on the first row, let's add to the output stream
    output0buffer.addrow()
    output0buffer.column1 = column1
    output0buffer.column2 = row.column1 - column1
    column1 = row.column1.value
    end if
    counter = counter + 1
    end sub

    I need to move on to something else at the moment, but the above pseudo code will not return the last row. I'll leave that to you.




  • ThunderRock

    Thanks, I'll try it out and report back.
  • SuperSaiyanZero

    Yes...
  • Accessing previous row in Asynch Script Component