Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)dim result() as Single dim tmp() as byte dim a as variant dim sngResult as Single Static n as integera = mscomm1.input tmp = a CopyMemory sngResult, tmp, 4 Redim Preserve result(n) result(n) = sngResult n = n + 1
Private Sub Command1_Click() Dim x As Single Dim y As Single Dim i As Integer Dim Byt_X(3) As Byte x = 3.1415926 CopyMemory Byt_X(0), x, 4 For i = 0 To 3 Debug.Print Byt_X(i) Next CopyMemory y, Byt_X(0), 4 Debug.Print yEnd Sub
浮点数提取出来并赋值给 result(). //// Option Explicit Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Sub Command1_Click() Dim x As Single Dim y As Single Dim i As Integer Dim Byt_X(3) As Byte x = 3.1415926 CopyMemory Byt_X(0), x, 4 For i = 0 To 3 Debug.Print Byt_X(i) Next CopyMemory y, Byt_X(0), 4 Debug.Print yEnd Sub
标准单精度浮点数的内存存储格式都是低位在前,高位在后,若你的数据是标准Single类型,可直接接收。 dim result() as Single Winsock1.GetData result, vbArray + vbSingle
我的回复
dim tmp() as byte
dim a as variant
dim sngResult as Single
Static n as integera = mscomm1.input
tmp = a
CopyMemory sngResult, tmp, 4
Redim Preserve result(n)
result(n) = sngResult
n = n + 1
Dim x As Single
Dim y As Single
Dim i As Integer
Dim Byt_X(3) As Byte
x = 3.1415926
CopyMemory Byt_X(0), x, 4
For i = 0 To 3
Debug.Print Byt_X(i)
Next
CopyMemory y, Byt_X(0), 4
Debug.Print yEnd Sub
浮点数提取出来并赋值给 result(). ////
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Sub Command1_Click()
Dim x As Single
Dim y As Single
Dim i As Integer
Dim Byt_X(3) As Byte
x = 3.1415926
CopyMemory Byt_X(0), x, 4
For i = 0 To 3
Debug.Print Byt_X(i)
Next
CopyMemory y, Byt_X(0), 4
Debug.Print yEnd Sub
dim result() as Single
Winsock1.GetData result, vbArray + vbSingle