Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Craig's auto increment function
Message
From
08/06/2008 18:47:00
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01322383
Message ID:
01322431
Views:
17
Set it as the default value for the key field and make GetKey be a Stored Proc in the DBC. That way, the value will be automatically populated.


>Suppose I use my table client DBF, buffered as 5
>I want to use Craig's auto increment funcion
>
>And then I have a buttom to save my data,
>and In click event I have:
>
>select client
> tableupdate ()
>
> Where should I use the funcion?
>
>Before or after the "client" tableupdate ()
>
>Thanks
>
>
>
>GetKey("Client")
>
>*********************************************
>FUNCTION GetKey
>LPARAMETERS tcTable
>
>LOCAL lnArea, llOpened, liRetVal
>
>* Save current work area
>lnArea = SELECT()
>llOpened = .F.
>
>IF !USED("Keys")
> USE Keys IN 0 SHARED
> llOpened = .T.
>ENDIF
>SELECT Keys
>SET ORDER TO TAG Table
>
>* FLOCK seems to work a bit better than RLOCK.
>* I've never had a problem with it.
>DO WHILE !FLOCK()
>ENDDO
>
>SEEK UPPER(tcTable)
>IF FOUND()
> liRetVal = NextId
> REPLACE NextId WITH NextId + 1
>ELSE
> INSERT INTO Keys (Table, NextId) VALUES (tcTable, 2)
> liRetVal = 1
>ENDIF
>
>FLUSH
>UNLOCK
>
>IF llOpened
> USE IN Keys
>ENDIF
>
>SELECT (lnArea)
>RETURN liRetVal
>**************************************************
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform