LSet有关问题
LSet问题
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type Bbyte
nBytes(3) As Byte
End Type
Private Type Lab1
fSingle As Single
End Type
Private Type Lab2
LongData As Long
End Type
Private Type Lab3
fSingle As Single
End Type
Private Sub Command1_Click()
Dim GetValue As Bbyte
Dim FGetValve As Lab1
Dim test As String
' GetValue.nBytes(3) = AsciiToDec(Recive(startNum + 7)) * 16 + AsciiToDec(Recive(startNum + 8))
' GetValue.nBytes(2) = AsciiToDec(Recive(startNum + 9)) * 16 + AsciiToDec(Recive(startNum + 10))
' GetValue.nBytes(1) = AsciiToDec(Recive(startNum + 11)) * 16 + AsciiToDec(Recive(startNum + 12))
' GetValue.nBytes(0) = AsciiToDec(Recive(startNum + 13)) * 16 + AsciiToDec(Recive(startNum + 14))
GetValue.nBytes(3) = 65
GetValue.nBytes(2) = 176
GetValue.nBytes(1) = 0
GetValue.nBytes(0) = 0
LSet FGetValve = GetValue
MsgBox Str(FGetValve.fSingle)
End Sub
Private Sub Command2_Click()
Dim j, i As Single
Dim k As Integer
Dim mybyte(3) As Byte
mybyte(0) = 65
mybyte(1) = 176
mybyte(2) = 0
mybyte(3) = 0
For k = 0 To 3
CopyMemory i, mybyte(k), 4
j = j + i
Next k
MsgBox Str(j)
End Sub
如何能够和Command1和Command2得到的值一样?
------解决方案--------------------
Private Sub Command2_Click()
Dim j, i As Single
Dim k As Integer
Dim mybyte(3) As Byte
mybyte(0) = 65
mybyte(1) = 176
mybyte(2) = 0
mybyte(3) = 0
For k = 0 To 3 \ 2
mybyte(k) = mybyte(k) Xor mybyte(3 - k)
mybyte(3 - k) = mybyte(k) Xor mybyte(3 - k)
mybyte(k) = mybyte(k) Xor mybyte(3 - k)
Next
CopyMemory i, mybyte(0), 4
Print Str(i), mybyte(0), mybyte(1), mybyte(2), mybyte(3)
End Sub
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type Bbyte
nBytes(3) As Byte
End Type
Private Type Lab1
fSingle As Single
End Type
Private Type Lab2
LongData As Long
End Type
Private Type Lab3
fSingle As Single
End Type
Private Sub Command1_Click()
Dim GetValue As Bbyte
Dim FGetValve As Lab1
Dim test As String
' GetValue.nBytes(3) = AsciiToDec(Recive(startNum + 7)) * 16 + AsciiToDec(Recive(startNum + 8))
' GetValue.nBytes(2) = AsciiToDec(Recive(startNum + 9)) * 16 + AsciiToDec(Recive(startNum + 10))
' GetValue.nBytes(1) = AsciiToDec(Recive(startNum + 11)) * 16 + AsciiToDec(Recive(startNum + 12))
' GetValue.nBytes(0) = AsciiToDec(Recive(startNum + 13)) * 16 + AsciiToDec(Recive(startNum + 14))
GetValue.nBytes(3) = 65
GetValue.nBytes(2) = 176
GetValue.nBytes(1) = 0
GetValue.nBytes(0) = 0
LSet FGetValve = GetValue
MsgBox Str(FGetValve.fSingle)
End Sub
Private Sub Command2_Click()
Dim j, i As Single
Dim k As Integer
Dim mybyte(3) As Byte
mybyte(0) = 65
mybyte(1) = 176
mybyte(2) = 0
mybyte(3) = 0
For k = 0 To 3
CopyMemory i, mybyte(k), 4
j = j + i
Next k
MsgBox Str(j)
End Sub
如何能够和Command1和Command2得到的值一样?
------解决方案--------------------
Private Sub Command2_Click()
Dim j, i As Single
Dim k As Integer
Dim mybyte(3) As Byte
mybyte(0) = 65
mybyte(1) = 176
mybyte(2) = 0
mybyte(3) = 0
For k = 0 To 3 \ 2
mybyte(k) = mybyte(k) Xor mybyte(3 - k)
mybyte(3 - k) = mybyte(k) Xor mybyte(3 - k)
mybyte(k) = mybyte(k) Xor mybyte(3 - k)
Next
CopyMemory i, mybyte(0), 4
Print Str(i), mybyte(0), mybyte(1), mybyte(2), mybyte(3)
End Sub