IB Statements/aschex

From CometWiki

Jump to: navigation, search

ASCHEX function

Syntax: ASCHEX(string-argument, numeric-error-argument)

Discussion: The ASCHEX function converts an ASCII hex string to its equivalent ASCII value.

The string-argument represents the string to be converted. Each two bytes of this string-argument must represent one ASCII character (this function provides the conversion to ASCII). The string-argument may be a string constant, a single-element string variable, a string array element, a string expression, or a string function.

The numeric-error-argument reports the success or failure of the conversion. It is set to 1 if there is a conversion error; otherwise, it is set to 0. The numeric-error-argument must be a single-element numeric variable or a numeric array element.

If there is a conversion error (i.e., if the string-argument contains non-hex characters), the ASCHEX function returns a null result.

Note: The HEXASC function performs the opposite function of ASCHEX (HEXASC converts a hex string to its ASCII hex equivalent, character for character).

Example: VALUE$ = ASCHEX(STR$,ERR)

In the above example, the variable STR$ contains a string of characters in ASCII hex form. These characters are converted to ASCII string form and stored in the variable VALUE$. The variable ERR stores a 0 or 1 to report the success of the conversion. For example, if STR$ equals "313233", VALUE$ will equal "123" (because "31" in hex is "1" in ASCII, etc.), and ERR will equal 0 (indicating a successful conversion).

Or, if STR$ equals "434F4D4554", VALUE$ will equal "COMET" (because "43" in hex is "C" in ASCII, "4F" represents "0", etc.), and ERR will equal 0.

Personal tools