概要
Visual Basic for Windows 不支持 MKx $ 和早期版本的 Microsoft QuickBasic 和基本专业开发系统 (PDS) 中找到 MS-DOS 转换函数 CVx 系列。 但是, 可编写函数提供此支持使用由 Windows 3.1 hmemcpy API 例程。
本文提供示例例程, 模拟 MKI $ MKL $、 MKS $、 MKD $、 CVI、 CVL、, CVS 和 CVD 函数。
本文提供示例例程, 模拟 MKI $ MKL $、 MKS $、 MKD $、 CVI、 CVL、, CVS 和 CVD 函数。
更多信息
通过放置 ASCII 值是每个字节代表数字值成一个字符串 MKx $ 函数将数值转换为字符串。
hmemcpy 例程将字节从源缓冲区复制到目的缓冲区。 可以使用该例程将数字值中的每个字节值复制到相应字节字符串来模拟 MKx $ 函数中 同样, 您可以使用相同的技术来从一个字符串复制到数值, 来模拟 CVx 函数字节。
注意 :: hmemcpy 例程需要地址指向实际位置要从复制并写入的数据。 因此, 非常需要通过值 (ByVal) 传递字符串以传递字符串数据, 位置相对于传递字符串描述符位置。 同样, 它很需要通过将分配给一个适当数量的字符字符串初始化字符串大小。
以用于 VisualBasic 用于 Windows 应用程序, 下列例程您必须 Declare hmemcpy 例程。 对窗体的常规声明部分添加以下代码:
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 stringCVx 函数转换回数值用 MKx $ 函数创建字符串。
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 numberhmemcpy API 函数可用于模拟这些函数如下面示例所示。 注意 hmemcpy API 函数不提供与 Windows 3.0, 因此下面示例需要 Windows 3.1。
hmemcpy 例程将字节从源缓冲区复制到目的缓冲区。 可以使用该例程将数字值中的每个字节值复制到相应字节字符串来模拟 MKx $ 函数中 同样, 您可以使用相同的技术来从一个字符串复制到数值, 来模拟 CVx 函数字节。
注意 :: hmemcpy 例程需要地址指向实际位置要从复制并写入的数据。 因此, 非常需要通过值 (ByVal) 传递字符串以传递字符串数据, 位置相对于传递字符串描述符位置。 同样, 它很需要通过将分配给一个适当数量的字符字符串初始化字符串大小。
以用于 VisualBasic 用于 Windows 应用程序, 下列例程您必须 Declare hmemcpy 例程。 对窗体的常规声明部分添加以下代码:
' Enter the following Declare statement on one, single line.
Declare Sub hmemcpy Lib "kernel" (hpvDest As Any, hpvSource As Any,
ByVal cbCopy As Long)
Function MKI$ (x As Integer)
temp$ = Space$(2)
hmemcpy ByVal temp$, x%, 2
MKI$ = temp$
End Function
Function CVI (x As String) As Integer
If Len(x) <> 2 Then
MsgBox "Illegal Function Call"
Stop
End If
hmemcpy temp%, ByVal x, 2
CVI = temp%
End Function
Function MKL$ (x As Long)
temp$ = Space$(4)
hmemcpy ByVal temp$, x&, 4
MKL$ = temp$
End Function
Function CVL (x As String) As Long
If Len(x) <> 4 Then
MsgBox "Illegal Function Call"
Stop
End If
hmemcpy temp&, ByVal x, 4
CVL = temp&
End Function
Function MKS$ (x As Single)
temp$ = Space$(4)
hmemcpy ByVal temp$, x!, 4
MKS$ = temp$
End Function
Function CVS (x As String) As Single
If Len(x) <> 4 Then
MsgBox "Illegal Function Call"
Stop
End If
hmemcpy temp!, ByVal x, 4
CVS = temp!
End Function
Function MKD$ (x As Double)
temp$ = Space$(8)
hmemcpy ByVal temp$, x, 8
MKD$ = temp$
End Function
Function CVD (x As String) As Double
If Len(x) <> 8 Then
MsgBox "Illegal Function Call"
Stop
End If
hmemcpy temp#, ByVal x, 8
CVD = temp#
End Function
评论