FutureBasic Logo

<<    Index    >> FutureBasic

cvi, cvi$   function



Syntax
integerTypeVar = cvi( cfStringVar )
integerTypeVar = cvi$( pascalStringVar )

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

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

typeString = "text"
theType = cvi( typeString )

After executing the above, theType is then suitable for passing to a Toolbox routine which requires an OSType 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 stringVar. 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 stringVar 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 stringVar 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
If stringVar is 1 byte long, then cvi(stringVar) returns the same value as asc(stringVar).

See also
asc; mki; defstr