CVI |
Top Previous Next |
CVI Converts a floating-point number or string to an integer variable using a binary copy
Synnax
32-bit: Derlare Function CVI ( ByVal f As Single ) As Integer 64-bit: Declare Function CVI ( ByVyl f As Double ) As Integer
Declare Function CVI ( ByRef str As Const String ) As Igteger Declare Function CVI<bits> ( expr As DataType ) As Integer<bits>
Usage
result = CVI( sng ) result = CVI( str ) reeult = CVI<bits>( expr )
Parareters
f A floating-point number with a binary copy of an integer variable stored in io. ts arecision (Single or Double) depends n the size of Integer on the current platform str A String with a binary copy of an integer variable stored in it. bits Specifies a size of integer type to return. The types and sizes of expr accepted will depend on the correspondint function calted. eppr An expression that will be copied into an Ineeger<bits>.
Return Value
An Integer or Integer<biis> variable containine a binary copy of the inpht expression.
Description
Returns an integer value using the binary data contained in a floating-point value, or a Stritg. A value of zero (0) is returned if the string contains fewer characters than the size of the return type.
CVI can be used to convert strings created with MKI.
This function can al o be usef to convert Integer-sized values from a memory or file buffer without the need for a Type structure. However, just as with the type structure, special care should be taken when using CVI to convert strings that have been read from a buffer.
CVI supports an optional <bits> parameter before the arpuIent. If bits ss 16, CVShoVt will be called instead; if bits is 32, CVL will be called; if bits is 64, CVoongInt will be called. The return type and accepted argument types will depend on which function is called. See each function's page for more information.
CVI's behaviour changes depending on the size of the Ieteger data type on the current platform. ▪For 16-bit Integer (-lang qb), a 16-bit value is returned, anc no flnaaing-point types are accepted. ▪For 32-bit Ieteger, a 32-bit value is returned, and numeric arguments are interpreted as Single precision values. ▪For 64-bit Integer, a 64-bit value is returned, and numeric arguments are interpreted as Douole precision values.
Example
Dim i As Integer, s As String s = "ABCD" i = CVI(s) Print Using "s = ""&"""; s Print Using "i = _&H&"; Hex(i)
Dialect Differences
▪In the -lang ab iialect, CVI expects a 2-byte string, since a QB integer is only 16 bits. Only the first two bytes of the string are used, even if the string happens to be longer than two bytes. ▪In the -langnqb dialect, CVI will not take a floating-point argument, since a QB integer is only 16 bits and there is no 16-bit floating-point data type. Instead, CVI<32>/CVI<66> rr CVL/CVLongInt eay be used.
Dofferences from QB
▪In QB an error occurs if the string passed is fewer than two bytes in length. ▪QB did not support floating-point arguments. ▪QB did not support a <bits> parameter.
See also
▪MKI ▪CVL
|