NAME

mki$, mks$, mkd$ - convert numeric value to string

SYNOPSIS

v$ = mki$(IntExp)
v$ = mks$(SngExp)
v$ = mkd$(DblExp)

DESCRIPTION

Each of mki$, mks$ and mkd$ causes the bytes of a numeric value to be stored in a string.  Mki$ converts an integer to a 2-byte string.  Mks$ converts a single-precision number to a 4-byte string.  Mkd$ converts a double-precision number to an 8-byte string.  These functions differ from str$ in that they convert the numeric value to a binary representation of the value rather than an ASCII (printable) representation.  The binary string may then be used in conjunction with lset or rset , and put to write the value to a binary data file.  The advantage of using the binary representation for storing numeric data is that it requires fewer bytes of file storage and less conversion overhead. 

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

cvi, cvs, cvd, field, get, lset, open, put, rset

from The Basmark QuickBASIC Programmer’s Manual by Lawrence Leinweber