Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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
share|improve this answer
    
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... –  LarsVegas Aug 23 '12 at 7:47
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.