Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generating Unique ID
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00586682
Message ID:
00587023
Views:
27
>To find the dbf of an alais:
>
>DBF(cAlais)
>
>This will returb the name of the dbf table and its path.
>

Right. I've determined, that in time of APPEND BLANK the current alias is indeed the table, we're appending. So, here is the changed function (I also changed name of NextID to FunLibID to avoid possible errors):
function GetNextID
lparameters tcAlias
local lnOldArea,lnNextID, lcDBC, lcOldSetDBC, llOpened, lcCurAlias
llOpened=.t.
*--- Variable Setup
lcCurAlias=upper(alias())
if empty(m.lcCurAlias)
	=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)
	=messagebox('You can not assign Next ID to a free table!',16,'Warning')
	return null
endif
lcOldSetDBC=set('database') && Save current status
if !dbused(m.lcDBC)
	open data (m.lcDBC)
	llOpened=.f. && Was not open before
endif
set database to (m.lcDBC) && Make this DBC current
*--- Go to FunLibID table to assign the next unique ID
local llFunLibIDUsed
llFunLibIDUsed = used('FunLibID')
if !OpenTble(addbs(justpath(m.lcDBC))+juststem(m.lcDBC)+"!"+"FunLibID",,,"Table")
	=messagebox('NextID table could not be opened!',16,'Warning')
	return null
endif
select FunLibID
if !seek(m.tcAlias)
	insert into FunLibID (table,id) 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.id with FunLibID.id + 1
		lnNextID = FunLibID.id
		unlock
	else
		return null
	endif
endif
if not m.llFunLibIDUsed
   use in FunLibID
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
>>>Nadya,
>>>
>>>
>>>lcFileName = JustFName(DBF(< AliasName >))
>>>
>>>
>>>lcFileName will be the DBF name for the alias in question
>>
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform