> SELECT 1 > GO BOTTOM > THISFORM.TEXT1.VALUE=BILLNO+1 >Problems with this as well as with the two other approaches can occur if You are in a MultiUser-Environment and work with Tablebuffering (but even without)
*========================================================= * * FUNCTION: NewID * *========================================================= FUNCTION NewID * Created...........: 20.Juli 2002, 11:36 Uhr * Changed...........: 26.07.2002 * Standort-ID wahlweise über Feld * in der Tabelle * Description.......: Neue ID für eine Tabelle erzeugen * Calling Samples...: ?NewID(<ExpC>[,<ExpN>[,<ExpL1>[,<ExpL2>]]]) * Parameters........: tc_Key, tn_Len, tl_NoFill, tl_Numeric * Returns...........: Character or Numeric lparameters tc_Key, tn_Len, tl_NoFill, tl_Numeric, tl_KeepOpen LOCAL ln_WasSel, lc_ID, lc_OldReproc, lv_RetVal, ln_Len tc_Key = iif(vartype(tc_Key) = "C", tc_Key, alias()) tn_Len = iif(vartype(tn_Len) $ "IN", tn_Len, 10) tl_NoFill = iif(vartype(tl_NoFill) = "L", tl_NoFill, .F.) && fill with leading zeroes tl_Numeric = iif(vartype(tl_Numeric) = "L", tl_Numeric, .F.) && return numeric *-- Keep the Control-File open if it *-- was not used before? tl_KeepOpen= iif(vartype(tl_KeepOpen) = "L", tl_KeepOpen, .F.) *-- Globale Standort-Variable *-- zur sicheren Unterscheidung *-- der Zähler if vartype(gc_Standort) # "C" public gc_StandOrt gc_StandOrt = "T" gc_Standort = InputBox("Standort-Kürzel eingeben","Standort-Kürzel",gc_Standort,10000, gc_Standort) endif ln_WasSel = select() lc_OldReproc = set("Reprocess") ll_WasUsed = used("PP_CONTROL") *-- von der Länge ggf. die Länge *-- des Prefix abziehen *-- if ! tl_Numeric *-- ln_Len = tn_Len - len(gc_Standort) *-- else ln_Len = tn_Len *-- endif set Reprocess to AUTOMATIC if ! ll_WasUsed use PP_CUST!PP_CONTROL in 0 endif select PP_CONTROL *-- Key auf die Länge des Feldes *-- auffüllen, damit ich nicht versehentlich *-- mal falsch lande tc_Key = padr(upper(tc_Key),len(PP_CONTROL.KEY_NAME)) if ! Seek(tc_Key, "PP_CONTROL", "KEY_NAME") *-- Schlüssel nicht gefunden, dann anlegen *-- und mit 2 initialisieren. Die jetzt be- *-- nötigte ID ist dann 1 insert into PP_CONTROL (KEY_NAME, VALUE, STANDORT, EDITABLE); values (tc_Key, str(2, len(PP_CONTROL.VALUE)), .F., .F.) lc_ID = str(1, ln_Len) else if rLock("PP_CONTROL") lc_ID = PP_CONTROL.VALUE replace PP_CONTROL.VALUE with str(val(allt(lc_ID))+1, len(PP_CONTROL.VALUE)) unLock endif endif do case case tl_Numeric *-- Als integer zurückgeben lv_RetVal = int(val(lc_ID)) case ! tl_Numeric and tl_NoFill *-- nicht aufgefüllt if PP_CONTROL.STANDORT ln_Len = ln_Len - len(gc_Standort) lv_RetVal = gc_Standort + padl(allt(lc_ID), ln_Len) else lv_RetVal = padl(allt(lc_ID), ln_Len) endif other *-- Character aufgefüllt mit Nullen if PP_CONTROL.STANDORT ln_Len = ln_Len - len(gc_Standort) lv_RetVal = gc_Standort + padl(allt(lc_ID), ln_Len, "0") else lv_RetVal = padl(allt(lc_ID), ln_Len, "0") endif endcase if ! ll_WasUsed and ! tl_KeepOpen and used("PP_CONTROL") use in PP_CONTROL endif select (ln_WasSel) set repro to (lc_OldReproc) return lv_RetVal *-- eof NewIDThe table PP_CONTROL looks like this:
KEY_NAME char(25) + INDEX VALUE char(25) EDITABLE LOGICAL STANDORT LOGICALKEY_NAME is the Key to the number You want. In Your case this would be "BILL_NUMBER" or something like that.