Here is a rewrite of your code:
i=1
c=0
SCAN
IF c=VAL(village)
i=i+1
ELSE
i=1
c=VAL(village)
ENDIF
REPLACE ccount WITH i
ENDSCAN
If village is treated as a numeric, why isn't the village column of type numeric? If it is a compound field (eg. "1 Village Name"), you should create a village table ( vcode i, vname c(24) ) and village in your main table with vcode.
The column name "ccount" seems inappropriate for how the column is used, I suggest "corder" or "csequence".
When is this ccount used? I seems that the ccount of any row could change after an insert, delete, sort, or set index. You should consider Mark's SQL.
>What I have is a code like this:
>
>
>GO TOP
>i=1 && i = counter variable
>c=0 && c is initialised to 0
>IF RECNO()=1
>c=VAL(village) &&c is assigned the first value of the village for the first rec ENDIF
>SCAN
> REPLACE ccount WITH i && value of i is assigned to the variable ccount
> IF c=VAL(village)
> i=1+1
> ELSE
> i=1
> ENDIF
> c=(village)
>ENDSCAN
>
>
>Tell me what I'm doing wrong here ....... coz I want the value of ccount to be incremented until the value of the village changes and i starts counting again from 1 til the next village etc etc ....
>
>Thanks,
>Richard.