VFP (unlike Access) does not have a built in counter field type. You have to
provide it for yourself. There are two ways of providing a unique ID, One way
involves generating a random number. The other providing a genuine numerical
counter which is incremented every time you add a record. You described your
need as a counter so I assume the latter method is what you want. Create a
table with a record in it that has a field which has been specied as a numeric
type. This table need have only one record and the record needs only the one
field. When you create this record, initialise the field to hold the value 1.
This field holds the next number to be used as the counter value. When you
add a new record to your table get this field value and store it in the record
(presumably to be used as some sort of record ID). Now add one to this value
and store it back into the field of your counter table.
Sounds easy doesn't it - sadly there is a fly in the ointment. What if you are
working on a network and one user has just picked up the counter value and,
while he is saving it in his new record, another user decides to add a record.
No matter how fast the first user acts to increment the counter and save it
back in the counter table, there is a chance that the second user will pick up
the same counter value as the first user. Woops! Two records with the same ID.
VFP, as every other major database development system, has a facility of
locking a record or even a whole file. Look up the Foxpro command RLOCK to
see how to lock a record. So the first user locks the counter record, the
second user tries to lock the record but can't (RLOCK returns false for her).
So the second user knows to wait for the first user to finish (and UNLOCK the
record) before she gets the counter for her use (and by now it has been
properly incremented).
In practice it is not easy to write bullet proof multiuser applications. VFP
does make your life a lot easier with buffered data handling but you will
still have to get your hands dirty to write the counter routines. But there
*IS AN ALTERNATIVE* Download the TRUE class library for VFP from compuserve
(Tom Retrigs data base containter extender) in which he provides a function for
generating and incrementing a counter. You will have a steep learning curve
understanding what TRUE is all about but the result is likely to be a lot more
secure than writing the code yourself if you are new to Foxpro. TRUE can
also add a lot more functionality to application apart from the counter. If
you can't find TRUE.ZIP on FTP or compuserve drop me an email.
Cheers
Mike
2. Access to Other ODBC database
3. Visual FoxPro indexing in Visual Basic
4. Cognos Powerplay - Upfront xml development
5. access table updated by Visual Basic passed on to visual Foxpro
6. corresponding data type for TEXT (tsql) in ADO?
7. Visual Foxpro or Visual Basic
8. Kerberos support interfering with normal access?
9. Visual Basic 6 and Visual Foxpro
10. Visual Basic 5/6 vs Visual FoxPro 5/6
11. Visual Basic vs Visual FoxPro
12. Visual Basic 4.0 and Visual FoxPro 3.0 databases
13. Visual Basic vs. Visual Foxpro