
How to emulate MKI$ and CVI in Visual Basic 5 and Windows95
Nino-
How about these? If you need the MBF
flavors also, let me know.
Joe LeVasseur
___________snip_________________________
Option Explicit
' Old Basic routines, unsupported in VB4/5
' uses RtlMoveMemory to replace hMemCpy-
' since hMemCpy is not exported in Win32.
' Adapted from article in KB
'////////////////////////////////////////////////
Declare Sub hMemCpy Lib "KERNEL32" Alias "RtlMoveMemory" _
(hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Function MKI(x As Integer) As String
Dim szTemp As String
szTemp = Space$(2)
hMemCpy ByVal szTemp, x, 2
MKI = szTemp
End Function
Function CVI(x As String) As Integer
Dim iTemp As Integer
If Len(x) <> 2 Then
MsgBox "Illegal Function Call"
Exit Function
End If
hMemCpy iTemp, ByVal x, 2
CVI = iTemp
End Function
Function MKL(x As Long) As String
Dim szTemp As String
szTemp = Space$(4)
hMemCpy ByVal szTemp, x, 4
MKL = szTemp
End Function
Function CVL(x As String) As Long
Dim lTemp As Long
If Len(x) <> 4 Then
MsgBox "Illegal Function Call"
Exit Function
End If
hMemCpy lTemp, ByVal x, 4
CVL = lTemp
End Function
Function MKS(x As Single) As String
Dim szTemp As String
szTemp = Space$(4)
hMemCpy ByVal szTemp, x, 4
MKS = szTemp
End Function
Function CVS(x As String) As Single
Dim sTemp As Single
If Len(x) <> 4 Then
MsgBox "Illegal Function Call"
Exit Function
End If
hMemCpy sTemp, ByVal x, 4
CVS = sTemp
End Function
Function MKD(x As Double) As String
Dim szTemp As String
szTemp = Space$(8)
hMemCpy ByVal szTemp, x, 8
MKD = szTemp
End Function
Function CVD(x As String) As Double
Dim dTemp As Double
If Len(x) <> 8 Then
MsgBox "Illegal Function Call"
Exit Function
End If
hMemCpy dTemp, ByVal x, 8
CVD = dTemp
End Function
________snip_____________________________
--
***********************************************************
Microsoft Dev MVP- Visual Basic
"To none will we sell, to none deny or delay,
right or justice." Magna Carta (June 15, 1215)
**********************************************************
PS- Please reply to the newsgroup- except in the
case of flames, insults, etc. (Don't bother.)
Quote:
> Visual Basic does not support the MKx$ and CVx family of conversion
> functions.
> I found Article Q87970 in Microsoft Knoeledge Base which solves the
> problem using Windows HMemCpy API routine but it doesn't work with VB5
> and Windows95.
> Is there someone able to help me?
> Thanks,
> Nino