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 a As Double
Dim buff() As Byte
ReDim buff(7)
a = 12345.6789
CopyMemory buff(0), a, 8 '将Double型变量转为字节数组
Dim i As Long
For i = 0 To UBound(buff)
Debug.Print buff(i)
Next
Dim b As Double
CopyMemory b, buff(0), 8 '将字节数组转为Double型变量
Debug.Print b
End Sub
Private Sub Command2_Click() '单精度
Dim a As Single
Dim buff() As Byte
ReDim buff(3)
a = 12345.6789
Debug.Print a
CopyMemory buff(0), a, 4 '将Double型变量转为字节数组
Dim i As Long
For i = 0 To UBound(buff)
Debug.Print buff(i)
Next
Dim b As Single
CopyMemory b, buff(0), 4 '将字节数组转为Double型变量
Debug.Print b
End Sub