CVBYT, CVCUR, CVCUX, CVD, CVDWD, CVE, CVI, CVL, CVQ, CVS and CVWRD functions

Purpose

Extracts numeric data from an ANSI string.

Syntax

bytevar?         = CVBYT(stringexpr [, offset])

curvar@          = CVCUR(stringexpr [, offset])

cuxvar@@         = CVCUX(stringexpr [, offset])

doublevar#       = CVD  (stringexpr [, offset])

doublewordvar??? = CVDWD(stringexpr [, offset])

extendedvar##    = CVE  (stringexpr [, offset])

integervar%      = CVI  (stringexpr [, offset])

longintvar&      = CVL  (stringexpr [, offset])

quadintvar&&     = CVQ  (stringexpr [, offset])

singlevar!       = CVS  (stringexpr [, offset])

wordvar??        = CVWRD(stringexpr [, offset])

Remarks

The CVx functions return a number corresponding to a binary pattern stored in a ANSI string value.  The binary pattern is the internal format used by PowerBASIC to store these values in memory.  This format follows the IEEE standard wherever it applies.  The MKx$ functions are complementary to the CVx functions.  Do not confuse these functions with the VAL function, which converts a number stored as a printable text string (such as "123.45") into a numeric expression.

In all but the most extreme cases, StringExpr must be an ANSI string or UDT which consists of single bytes.  WIDE (Unicode) strings consist of a series of 2-byte words which will generally yield undefined results.

The CVx functions allow you to retrieve values beyond the first byte of the StringExpr.  In this case, the optional offset parameter tells the byte position where the conversion should begin.  This is the byte position, not the character position, even with a WIDE StringExpr.  If Offset is not given, it is presumed to be one (1).

For example: "Value& = CVL(x$, 3)" would extract the 3rd through 6th bytes of x$ and convert these 4 bytes to the corresponding Long-integer value.  In this example, x$ must be at least 6 bytes long.

Function

Variable

Converts to

CVBYT

1-byte string

Byte

CVCUR

8-byte string

Currency

CVCUX

8-byte string

Extended-currency

CVD

8-byte string

Double-precision float

CVDWD

4-byte string

Double-word

CVE

10-byte string

Extended-precision float

CVI

2-byte string

Integer

CVL

4-byte string

Long-integer

CVQ

8-byte string

Quad-integer

CVS

4-byte string

Single-precision float

CVWRD

2-byte string

Word

Restrictions

Expressions involving Numeric Equates and conditional compilation (#IF) may also include the CVQ function.  This allows you to easily assign numeric values to an equate, based upon a meaningful mnemonic.  In this context, the CVQ expression is limited to a length of eight bytes.  For example:

%Mode  = CVQ("DEBUG")

%Style = CVQ("Cool")

CVS limits string display to seven significant digits.

See also

MKBYT$ and associated functions