浮点数怎么转换到字节数组,用于串口传输
我看了一些贴,和帮助
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As byte, ByVal Source As object, ByVal Length As Integer)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim kongqimidu As Single '4字节(float)
Dim buffer(3) As Byte
kongqimidu = 8.73
Try
CopyMemory(buffer(0),kongqimidu, 4)
Catch ex As Exception
MsgBox(ex)
End Try
End Sub
每次运行到copymemory,总是报"未将对象引用设置到对象的实例",求救。
问问是copymemory使用不当
或者还有没有其他的方法可以实现将浮点数转换到字节数组里,我需要将字节数组传送到mscomm控件中,谢谢