#DEFINE DB_SRCLOCALVIEW 1 FUNCTION NewID(tcAlias) *-- Special thanks to Steve Sawyer for his work on allowing *-- both character and numeric keys to work with this routine. LOCAL lcAlias, ; luID, ; lnOldReprocess, ; lnOldArea lnOldArea = SELECT() IF PARAMETERS() < 1 lcAlias = ALIAS() IF CURSORGETPROP("SOURCETYPE") = DB_SRCLOCALVIEW *-- Attempt to get base table lcAlias = UPPER(CURSORGETPROP("TABLES")) lcAlias = SUBSTR(lcAlias, AT("!", lcAlias) + 1) *------------------------------------------------- *-- If NewID() is specified as the default value *-- in a view field rather than a table, there may *-- be multiple database references to truncate *------------------------------------------------- IF AT(",", lcAlias) > 0 lcAlias = SUBSTR(lcAlias, 1, AT(",", lcAlias) - 1) ENDIF ENDIF ELSE lcAlias = UPPER(tcAlias) ENDIF luID = "" lnOldReprocess = SET('REPROCESS') *-- Lock until user presses Esc SET REPROCESS TO AUTOMATIC IF !USED("websecid") USE websecid IN 0 ENDIF SELECT websecid IF SEEK(lcAlias, "websecid", "keyname") IF RLOCK() luID = IIF(websecid.type = 'C', websecid.value, VAL(websecid.value)) REPLACE websecid.value WITH EVAL(websecid.incrementprocedure) UNLOCK ENDIF ENDIF SELECT (lnOldArea) SET REPROCESS TO lnOldReprocess IF websecid.Type = 'C' RETURN TRIM(luID) ELSE RETURN luID ENDIF ENDFUNC FUNCTION IncrementBase10(tcValue) *-- Increments a base 10 number. This function assumes that *-- the length of tcValue represents the maximum number of *-- possible digits for this base 10 number. LOCAL lnStringLength lnStringLength = LEN(tcValue) RETURN PADL(RIGHT(ALLT(STR(VAL(tcValue) + 1)), lnStringLength), lnStringLength) ENDFUNC