NAME

cvi, cvs, cvd - map string variables to numeric variables

SYNOPSIS

v% = cvi(StrExpr)
v! = cvs(StrExpr)
v# = cvd(StrExpr)

DESCRIPTION

Each of the functions cvi, cvs, and cvd performs a type conversion from a string consisting of characters containing the bytes of a binary encoded numeric value into a numeric value of the appropriate numeric type.  Cvi converts a two-byte string to integer type.  Cvs converts a four-byte string to single-precision type.  Cvd converts an eight-byte string to double-precision type.  The actual bytes of data are not changed by cvi, cvs, and cvd; only the type of the value is changed. 

StrExpr may be any string expression, but only the first 2, 4, or 8 bytes are used by cvi, cvs, and cvd, respectively. 

EXAMPLE

This example illustrates the use of mki$ and cvi, and mks$ and cvsMkd$ and cvd follow the same pattern as mks$ and cvs
	    defint n
	    defsng a
	    print "writing..."
	    open "cvt.out" as #1 len = 6
	    field #1, 2 as no$, 4 as amt$
	    no = 1
	    while no
		input "Enter chk #, amt (or 0,0 when done)"; no, amt
	 40	lset no$ = mki$(no)
	 50	lset amt$ = mks$(amt)
		put #1
	    wend
	    close #1
	    print "reading..."
	    open "cvt.out" as #1 len = 6
	100 field #1, 2 as no$, 4 as amt$
	    no = 1
	    while no
	110	get #1
	120	no = cvi(no$)
	130	amt = cvs(amt$)
		if no then print using "##### $$#,###.##"; no, amt
	    wend
	    close #1
This example uses a random file (#1) which has fields defined as in line 100.  Line 110 reads a record from the file.  Line 120 uses the cvi function to interpret the first two bytes (no$) of the record as an integer; no$ was originally a number which was written to the file using the mki$ function in line 40.  Line 130 uses the cvs function to interpret the first four bytes (amt$) of the record as a single-precision number; amt$ was originally a number which was written to the file using the mks$ function in line 50. 

SEE ALSO

mki$, mks$, mkd$

DIAGNOSTICS

If StrExpr is too short, an "Illegal function call" error occurs. 

from The Basmark QuickBASIC Programmer’s Manual by Lawrence Leinweber