Obtiene un GUID en formato {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}
*!* Obtiene un GUID en formato {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}
*!* Sintaxis: GetGuid()
*!* Valor devuelto: lcGuid
FUNCTION GetGuid
LOCAL lnCnt, lcGuid, lcData1, lcData2, lcData3, lcData4, lcData5
*!* Instrucciones DECLARE DLL para manipular obtener un GUID
DECLARE INTEGER CoCreateGuid IN Ole32.DLL STRING @lpGuid
*!* Valores
lnCnt = 0
lcGuid = ""
lcData1 = ""
lcData2 = ""
lcData3 = ""
lcData4 = ""
lcData5 = ""
lpGuid = REPLICATE(CHR(0), 17)
*!* Obtener el GUID
IF CoCreateGuid(@lpGuid) = 0
*!* Valores
*!* Los 8 primeros dígitos
lcData1 = RIGHT(TRANSFORM(StrToLong(LEFT(lpGuid, 4)), "@0"), 8)
*!* Los 4 segundos dígitos
lcData2 = RIGHT(TRANSFORM(StrToLong(SUBSTR(lpGuid, 5, 2)), "@0"), 4)
*!* Los 4 terceros dígitos
lcData3 = RIGHT(TRANSFORM(StrToLong(SUBSTR(lpGuid, 7, 2)), "@0"), 4)
*!* Los 4 cuartos digitos
lcData4 = RIGHT(TRANSFORM(StrToLong(SUBSTR(lpGuid, 9, 1)), "@0"), 2);
+ RIGHT(TRANSFORM(StrToLong(SUBSTR(lpGuid, 10, 1)), "@0"), 2)
lcData5 = ""
*!* Los 12 digitos finales
FOR lnCnt = 1 TO 6
lcData5 = lcData5 + RIGHT(TRANSFORM(StrToLong(SUBSTR(lpGuid, 10 + lnCnt, 1))), 2)
ENDFOR
*!* Verifica la longitud de los 12 digitos finales. Si son menores de 12 es que el resto son 0
IF LEN(lcData5) < 12
lcData5 = lcData5 + REPLICATE("0", 12 - LEN(lcData5))
ENDIF
*!* Valores
lcGuid = "{" + lcData1 + "-" + lcData2 + "-" + lcData3 + "-" + lcData4 + "-" + lcData5 + "}"
ENDIF
*!* Retorno
RETURN lcGuid
ENDFUNC
*!* Convierte un 4-byte CHARACTER STRING a un LONG INTEGER
*!* Sintaxis: StrToLong(tcLongStr)
*!* Valor devuelto: lnRetval
*!* Argumentos: tcLongStr
*!* tcLongStr especifica el 4-byte character string a convertir
FUNCTION StrToLong
LPARAMETERS tcLongStr
LOCAL lnCnt, lnRetVal, lcLongStr
*!* Valores
lnRetVal = 0
lcLongStr = IIF(EMPTY(tcLongStr), "", tcLongStr)
*!* Convertir
FOR lnCnt = 0 TO 24 STEP 8
lnRetVal = lnRetVal + (ASC(lcLongStr) * (2^lnCnt))
lcLongStr = RIGHT(lcLongStr, LEN(lcLongStr) - 1)
NEXT
*!* Retorno
RETURN lnRetVal
ENDFUNC
Hola, al ejecutar la funcion me genera el resultado del codigo asi: { ; @0-; @0-@0@0-919355376540}, porque?
ResponderBorrarYa está corregido el código. El formato del parámetro de la función TRANSFORM() tenía caracteres inválidos
Borrar