function GetNextID && Function to generate Next_ID field lparameters tcAlias local lnOldArea,lnNextID, lcDBC, lcOldSetDBC, llOpened, lcCurAlias llOpened=.t. *--- Variable Setup lcCurAlias=upper(alias()) if empty(m.lcCurAlias) && Should not ever happen =messagebox("No table open...",16,"Error") return null endif tcAlias = iif(empty(m.tcAlias),m.lcCurAlias,upper(m.tcAlias)) lnOldArea = select() lnNextID = 0 lcDBC=cursorgetprop('database',m.lcCurAlias) && Return the name of owning database if empty(m.lcDBC) && Should not happen * =messagebox('You can not assign Next ID to the free table!',16,'Warning') return null endif lcOldSetDBC=set('database') && Save current database if !dbused(m.lcDBC) && Could not happen open data (m.lcDBC) llOpened=.f. && Was not open before endif set database to (m.lcDBC) && Make this DBC current if !OpenTble(m.lcDBC+"!"+"FunLibID",,,"cTable") =messagebox('NextID table could not be opened!',16,'Error') return null && Error would be produced by DBC about referential integrity endif select FunLibID if !seek(m.tcAlias) && New empty table insert into FunLibID (cTable,nID) values (m.tcAlias,1) lnNextID = 1 else *--- RLOCK will attempt the lock indefinately, because it would be bad to return 0 (the alternative). *--- User will be able to cancel attempt if in a deadlock by pressing the ESC key. if rlock() replace FunLibID.nID with FunLibID.nid + 1 lnNextID = FunLibID.nID unlock else lnNextID=null && Error would be produced by DBC about referential integrity endif endif *--- Return to prior workarea. select (m.lnOldArea) if not m.llOpened close database endif if !empty(m.lcOldSetDBC) set database to (m.lcOldSetDBC) endif return m.lnNextID>Thanks Nadya
>>>LOCAL lnOldSel,lnCompteur >>>lnOldSel=SELECT() >>>lnCompteur=0 >>>IF ! USED('key_no') >>> USE key_no IN 0 >>>ENDIF >>>SELECT key_no >>>1 >>>DO WHILE (NOT RLOCK()) AND (INKEY(0.1)=0) AND lnCompteur<=25 >>> lnCompteur=lnCompteur+1 >>>ENDDO >>>REPLACE NUMERO WITH NUMERO+1 >>>UNLOCK >>>SELECT(lnOldSel) >>>RETURN key_no.NUMERO >>> >>>>>>