Monday, May 7, 2007

Fungsi untuk ngebuat unik id

///////////////////////////////////////////////////////////////////////////////////////
//
// function : f_getrowid
// Purpose : Ngebuat unik id
// Scope : Public
// Arguments : none
// Returns : unik id
//
// Modification Log
// ================
// NAME VER DATE DESCRIPTION
//
//------------------ ---------------------------------------------
// setiawanthea 1.0
//
//////////////////////////////////////////////////////////
/////////////////////////////
//--------------------------Start of declarations----------------------------//

decimal ldec_10, ldec_int
string ls_temp
string ls_62 = ''
char ic_simbol[]
string ls_simbol = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
integer ii

// Prepare string Array for row id
// prepare lambangan bilangan untuk row_id
for ii=1 to 62
ic_simbol[ii] = mid(ls_simbol,ii,1)
next


ldec_10 = dec(string(datetime(today(),now()),'yyyymmddhhmmssffff'))
// generates a unique rowid based on time
// convert ke bilangan basis 62
do until ldec_10 = 0
ls_temp = string(ldec_10 / 62)
ldec_int = dec(mid(ls_temp,1,pos(ls_temp,'.')))
//ldec_int = int(ls_temp)
if ldec_int = 0 then ldec_int = dec(mid(ls_temp,1,pos(ls_temp,',')))
ls_62 = ic_simbol[ldec_10 - 62 * ldec_int + 1] + ls_62
ldec_10 = ldec_int
loop

// Counter for Unique Guarantee
// counter untuk menjamin unique
if gl_cc > 99999 then gl_cc = 0
ls_62 += gs_id +string(gl_cc,'00000')
gl_cc ++
if isnull(ls_62) or Trim(ls_62) = "" then
ls_62 = string(gf_serverdate(),'yyyymmddhhmmssffff')
Messagebox("Error","Cannot Generate Row ID")
end if
return ls_62

No comments: