Page 1 of 1
Unique ID
Posted: Fri Jun 09, 2017 1:00 am
by cdmmaui
Hello,
Is there a function in FWH that creates a unique ID? I need to created a unique ID every time logs in to our system.
Thank you!
Re: Unique ID
Posted: Fri Jun 09, 2017 1:34 am
by hua
Re: Unique ID
Posted: Fri Jun 09, 2017 1:10 pm
by Rick Lipkin
Darrell
Here is how I create my Sql Primary keys .. this routine creates a unique character .. you can easily adapt to numeric as well.. The process is not elegant but works.
Rick Lipkin
Code: Select all
//---------------------
Static Func _GenTripsEid()
LOCAL nRAND, cRAND, oRs, cSQL, oERR
cSQL := "SELECT TRIPSEID from TRIPS"
oRs := TOleAuto():New( "ADODB.Recordset" )
oRs:CursorType := 1 // opendkeyset
oRs:CursorLocation := 3 // local cache
oRs:LockType := 3 // lockoportunistic
TRY
oRs:Open( cSQL,oCn )
CATCH oErr
MsgInfo( "Error in Opening TRIPS table to create TripsEid" )
RETURN("BOGUS")
END TRY
cRAND := 'BOGUS'
DO WHILE .T.
nRAND := nRANDOM(10000000000000000)
// 1 is reserved and 0 is a null key //
IF nRAND = 1 .or. nRAND = 0 .or. nRAND = NIL
LOOP
ENDIF
cRAND := STR(nRAND,17)
IF oRs:eof
ELSE
oRs:MoveFirst()
oRs:Find("tripseid = '"+cRAND+"'" )
ENDIF
IF oRs:eof
EXIT
ELSE
LOOP
ENDIF
EXIT
ENDDO
oRs:CLose()
RETURN( cRAND )