Helmut44

Compare previous field in field calculator

Discussion created by Helmut44 on Nov 21, 2011
Latest reply on Nov 22, 2011 by Helmut44
I tried to write my first phyton script today, because VBA is no more supported in ArcGis10 and VBScript does not allow static variables. Here is what I am trying to do:

I have 3 fields:

A     B     C
20    X     0=1
7     X     0
4     X     0
4     X     0
3     X     0
2     X     0
6     Y     0=1
3     Y     0
2     Y     0
102  Z     0=1
60    Z     0
58    Z     0
...    Z     0

I want to let the field calculator enter 1 in C, when the String in B changes and A is above 20.
So I need to compare the previous Value in B with the actual field and then check, weather the number in A is above 20.
This would have been the VBA Script (but doesn't work anymore because of static):
Static B as string
Dim C As Single
C = 0

If IsEmpty(B) Then
 C = 1
Else
 if not B = [B] and [A] > 20 then
   C = 1
  else
   C = 0
  end if
End If

B = [B]

return C



This is how far I got with phyton, but it's not working and I don't know why (possibly more than one reason):

lastB = "nothing"

 def compare(B):
 global lastB
 if not B = lastB:
  output = 1
 else:
 output = 0
lastB = B

return output

compare(!B!)


Can anyone explain me where I went wrong with the phyton script?

Outcomes