Using Microsoft Visual FoxPro 9, I have a custom function "newid()" inside of the stored procedures for Main:
function newId
parameter thisdbf
regional keynm, newkey, cOldSelect, lDone
keynm=padr(upper(thisdbf),50)
cOldSelect=alias()
lDone=.f.
do while not lDone
select keyvalue from main!idkeys where keyname=keynm into array akey
if _tally=0
insert into main!idkeys (keyname) value (keynm)
loop
endif
newkey=akey+1
update main!idkeys set keyvalue=newkey where keyname=keynm and keyvalue=akey
if _tally=1
lDone=.t.
endif
enddo
if not empty(cOldSelect)
select &cOldSelect
else
select 0
endif
return newkey
This function is used to generate a new ID for records added to the Database.
It is called as the Default value:

I would like to call this newid() function and retrieve its returned value.
When executing SELECT newid("TABLENAME")
The error: Invalid subscript reference is thrown
How can I call the newid() function and return the newkey in Visual FoxPro 9?
