Kbase P9903: How to get the hexadecimal representation of a visual basic variant data type variable obtained usin
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  11/03/2003 |
|
Status: Unverified
GOAL:
How to get the hexadecimal representation of a visual basic variant data type variable obtained using third party DLL function call.
FIX:
/* This solution assumes that the included DLL function call returns */
/* a valid raw data type value into the variable rResultReturned. */
DEFINE Variable rResultReturned AS RAW NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
DEFINE VARIABLE iByteData AS INTEGER NO-UNDO.
DEFINE VARIABLE cHexString AS CHARACTER NO-UNDO.
/* Define function to convert integers to their hexadecimal strings */
FUNCTION DecToHex RETURNS CHARACTER (INPUT iData AS INTEGER).
DEF VAR j AS INT NO-UNDO.
DEF VAR h AS CHAR NO-UNDO.
DO WHILE TRUE:
j = iData MODULO 16.
h = (IF j < 10 THEN STRING(j) ELSE CHR(ASC("A") + j - 10)) + h.
IF iData < 16 THEN LEAVE.
iData = (iData - j) / 16.
END.
RETURN (h).
END FUNCTION.
/* Store Visual Basic Variant variable result into the RAW variable */
ASSIGN
rResultReturned = Manager1.Message.Variables(1).ValueEx
cHexString = "".
/* Use the GET-BYTE function to process the result a byte at a time */
DO iCounter = 1 to LENGTH(rResultReturned):
iByteData = GET-BYTE(rResultReturned, iCounter).
cHexString = cHexString + DecToHex(iByteData).
END.
MESSAGE cHexString
VIEW-AS ALERT-BOX INFO BUTTONS OK.