Hans L


I have the following code to check for the last running number in table Idmsnum, insert the next number after the last current number into Idmsnum, and then insert that number into anothertable.Iswid

viidnom = 0
IF vcnev = 'New'
IF RECCOUNT('Idmsnum') = 0
viidnom = 1
ELSE
GO BOTTOM IN 'Idmsnum'
viidnom = Idmsnum.iid + 1
ENDIF
APPEND BLANK IN 'Idmsnum'
REPLACE iid WITH viidnom IN 'Idmsnum'
*
REPLACE iswid WITH viidnom
ENDIF
*
---------------------

REPLACE iswid WITH viidnom

works, that is, the added latest number is inserted into anothertable.Iswid.

However, somehow, either

APPEND BLANK IN 'Idmsnum'
or
REPLACE iid WITH viidnom IN 'Idmsnum'

does not work. I suspect APPEND BLANK.since there seem to be no new record in table Idmsnum after this code has run, and since REPLACE iswid WITH viidnom works fine. This code works in several other apps.

I don't expect anyone to have a straight answer, but perhaps someone can tell me where I should start to look. I have spend hours trying to resolve this.

Regards,

Hans L



Re: APPEND BLANK or REPLACE -- which one does not work

Hans L


Only had to ask! Just discovered that I had buffered table Idmsnum, and with no TABLEUPDATE(), it did not append a blank record. (Actually, I inserted TABELUPDATE()" earlier, but got an eror messge then too.)

Well, in any event, I deleted the buffering (not needed), and now, everything (I should be so lucky!) works okay.

Thanks for listening :-)

Regards,


Hans L





Re: APPEND BLANK or REPLACE -- which one does not work

CetinBasoz

Hi Hans,

You have solved it telling to aunt MarySmile

However be carefull, be very carefull. This approach is wide open to errors in a multiuser environment (I like to plan for multiuser even if it would be used standalone).

Consider this case:

Reccount is yet 0 for when user A asks for it.

viidnom = 0
IF vcnev = 'New'
IF RECCOUNT('Idmsnum') = 0
viidnom = 1
ELSE
GO BOTTOM IN 'Idmsnum'
viidnom = Idmsnum.iid + 1
ENDIF

user A gets to the line 'append blank' but to her chance before she does the append user B does the same check and sees reccount is 0. Both proceed with the same 0 case and create a record with value 1. I tried to simplify the case but in real life this kind of duplication might and do occur.

To solve the issue you need to use locking. In solution.app there is a NextId sample (name might not be exactly NextId but similar). Check it.

If your version of VFP has it, then autoinc field might be what you're looking for. Its locking is controlled by VFP itself and is a readonly field.

I don't know the purpose of this number, if it is for a primary key then maybe using a GUID (GloballyUniqueIDentifier) is a better approach (to me it is but developers have been divided into camps about it - integer vs GUID-).






Re: APPEND BLANK or REPLACE -- which one does not work

Hans L

Cetin, you are of course right in all of what you say above. I will have to start thinking of multiuser. The particular app I am dealing with now is for me only at the moment, but it might very well be for multiuse in the future. Thanks for pointing this out.

Regards,

Hans L

PS. I guess aunt Mary is deaf :-)




Re: APPEND BLANK or REPLACE -- which one does not work

Naomi Nosonovsky

Did you mean Auntee Emma principle www.ndragan.com/pv/emma.html





Re: APPEND BLANK or REPLACE -- which one does not work

Hans L

Yep, Naomi, that's what I was thinking of. I'm not sure what Cetin meant by Aunt Mary, but I guess it was the same thing.

Regards,

Hans L