Subject Re: autoincrement problem
From Mervyn Bick <invalid@invalid.invalid>
Date Tue, 17 Oct 2023 11:22:56 +0200
Newsgroups dbase.getting-started

On 2023/10/17 08:35, Charlie wrote:
> Hi Ken...  Thanks..  I tried that as an xdml function with a variable and then a hard number as below..  Doesn't seem to work for me.  Does the same thing.  New number is starting over.  Any suggestions?
>
> I did have success in dropping the field and then creating it again but that doesn't seem to be very code friendly.

While it is possible to remove the field and then recreate it, it is not
a good idea.  It will leave blanks in the field for existing records and
the value placed in new records will start from 1.  It will also destroy
the existing index on the field.

DBF7File.cc can be used to correct the value for new records and the
index can be rebuilt but it will still leave blanks in the existing
records.  It is not possible to manually replace the blank values with,
say, recno().

To be able to place values in the blank fields the field would need to
be created as INT (or DOUBLE if you use the table designer) which would
allow editing the field to replace blank values.  The field type would
then need to be changed to autoinc by editing the table header followed
by DBF7File.cc to set the autoinc value for the next new record.
Doable but definitely not for the faint-hearted. :-)


>
> function alttab()
> private x
> x = 0
> use floss.dbf
> go bottom
> x = lr +1

I assume the value in lr was 292

> close tables
> set procedure to :dUFLP:DBF7File.CC
> oDBF7File = new DBF7File( "floss.dbf" )
> oDBF7File.SetNextAutoIncValue( 293 )

Either

oDBF7File.SetNextAutoIncValue( x )
   or
oroDBF7File.SetNextAutoIncValue( 293 )

should work here

> oDBF7File = null
> close procedure :dUFLP:DBF7File.cc
> return

The next record appended to floss.dbf should show the value 293 in the
autoinc field.

If it doesn't we need to see your code.

Mervyn.