Article ID: 87970 - Last Review: December 12, 2003 - Revision: 2.0 How to Emulate MKI$ and CVI in VB Using Windows HMemCpy
This article was previously published under Q87970 SUMMARY
Visual Basic for Windows does not support the MKx$ and CVx family of
conversion functions found in earlier versions of Microsoft QuickBasic
and Basic Professional Development System (PDS) for MS-DOS. However,
you can write functions that provide this support using the hmemcpy
API routine provided by Windows version 3.1. This article provides example routines that simulate the MKI$, MKL$, MKS$, MKD$, CVI, CVL, CVS, and CVD functions. MORE INFORMATION
The MKx$ functions convert numeric values to strings by placing the ASCII
value of each byte that represents the numeric value into a string.
Function Description --------- --------------------------------------------------------- MKI$ Converts an integer to a 2-byte string MKL$ Converts a long-integer to a 4-byte string MKS$ Converts a single precision variable to a 4-byte string MKD$ Converts a double-precision variable to an 8-byte string
Function Description</H3>
--------- ---------------------------------------------------------
CVI Converts a 2-byte string created with MKI$ to an integer
CVL Converts a 4-byte string created with MKL$ to a long integer
CVS Converts a 4-byte string created with MKS$ to a single-
precision number
CVD Converts an 8-byte string created with MKD$ to a double-
precision number
The hmemcpy routine copies bytes from a source buffer to a destination buffer. You can use this routine to copy the value of each byte in a numeric value to a corresponding byte in a string to emulate the MKx$ functions. Similarly, you can use the same technique to copy the bytes from a string to a numeric value, to emulate the CVx functions. NOTE: The hmemcpy routine requires the addresses pointing to the actual location of the data to be copied from and written to. Therefore, it is necessary to pass strings by value (ByVal) in order to pass the location of the string data, as opposed to passing the location of the string descriptor. Similarly, it is necessary to initialize the string size by assigning the string to an appropriate number of characters. To use the following routines in your Visual Basic for Windows application, you must Declare the hmemcpy routine. Add the following code to the general declarations section of the form: REFERENCES
"Microsoft Windows SDK: Programmer's Reference," Volume 2: Functions,"
version 3.1
APPLIES TO
| Other Resources Other Support Sites
CommunityGet Help NowArticle Translations |






Windows Live
Facebook
Twitter
Linkedin
Digg it
Yahoo
Delicious
StumbleUpon
Yammer
Reddit
Technorati
FriendFeed
Email

Back to the top
