# ArcGIS field calculator: VBScript get data from previous row

When using the field calculator, how do I get data from the previous row in VBScript? In Python I'd do something like this:

``````for index, row in enumerate(rows,start=1):
row[index-1] += 5
``````

I'm using ArcGIS 9.3.1.

Let's assume I have a column `[Distance]` and all it's rows are `0`. How do I increment every row with 5 starting at row 1. So the first row remains `0`, second row'll be `5`, third `10` and so on.

This script is from the Easy Calculate 5.0 Scripts by Ianko Tchoukanski

This section goes in the code block. Set the `lInterval` and `lStart` values as necessary. In this case, `lInterval = 5` and `lStart = 0`.

``````Static rec As Long
Static i As Long
Dim lStart As Long
Dim lInterval As Long
'=================
'adjust start value and interval below
lStart =  0
lInterval = 5
'=================
If (i = 0) Then
rec = lStart
Else
rec = rec + lInterval
End If
i = i + 1
``````

Place this in the `[Field Name] =` area:

``````rec
``````
• Yeah mate, this is it. I just can't get my head around VBScript, I'm really looking forward to ArcGIS 10x when all you need is Python... Aug 23 '12 at 7:47

I can think of a crude, but quick way of achieving the end result.

Assuming the OID (or OBJECTID) starts from 0.
Put the following code in the Pre-logic script code area.

``````If [OBJECTID]=0 Then
result=0
Else
result=[OBJECTID] * 5
End If
``````

Under "Distance=", type "result" (without the quotes).

For an OBJECTID that does not start at 0, modify the pre-logic code as follows:
Again, assuming OID starts at 1000, modify as per your data.

``````If [OBJECTID]-1000=0 Then
result=0
Else
result=([OBJECTID]-1000) * 5
End If
``````

Regards
Ujjwal