Futurebasic/Language/Reference/cvi

From Wikibooks, open books for an open world
Jump to navigation Jump to search

CVI function[edit | edit source]

CVI[edit | edit source]

Function[edit | edit source]

✔ Appearance ✔ Standard ✔ Console

Syntax[edit | edit source]

var& = CVI(string$)

Description[edit | edit source]

This function converts the bytes in string$ into an integer value which has the same internal bit-pattern that string$ has. If string$ consists of 4 or more bytes, only its first 4 bytes are considered. If string$ consists of 1, 2 or 3 bytes, then CVI(string$) returns an 8-bit, 16-bit or 24-bit integer, respectively. If string$ is a null string, then CVI(string$) returns zero.

This function is useful for finding the integer form of such things as file types, creator signatures and resource types. For example:

ft$ = "TEXT"
theType& = CVI(ft$)

After executing the above, theType& is then suitable for passing to a Toolbox routine which requires a file-type parameter. theType& will also have the same value as the integer constant _"TEXT".

The size (in bytes) of the value returned by CVI depends on the length of string$. It does not depend on the current setting of DEFSTR BYTE/WORD/LONG. Therefore, if you want to assign the return value of CVI to a short integer variable, you must make sure that string$ is not longer than 2 bytes; otherwise, you'll get an unexpected value in your short integer variable. Similarly, if you want to correctly assign CVI's return value to a byte variable, you should make sure that string$ is not longer than 1 byte.

The MKI$ function is the inverse of CVI. Note, however, that the output of MKI$ does depend on the current setting of DEFSTR BYTE/WORD/LONG.

Note[edit | edit source]

If string$ is 1 byte long, then CVI(string$) returns the same value as ASC(string$).

See Also[edit | edit source]

DEFSTR; LONG; WORD; BYTE