'function function: turn a long integer value stored in an array
Public Function ShutoShuzu (shu As Long, ByRef shuzu () As Byte, beg the As Byte, zijie As Byte, Optional mode As Byte=0) As Boolean 'will be a Long value is placed into a 4 Byte array
On Error GoTo Errc
1 'parameters, shu archived long integer, and 2, array with shu deposited into shuzu, 3, beg in the original position in the array
'4, 5 zijie stored in the array to a few bytes, store mode order
Dim As a String, sP4 As String, sP3 As String, sP2 As String, sP1 As String
Dim As Byte B, c As String
ShutoShuzu=False
A=hex (shu)
B=Len (a)
The Select Case B
Case 1
C="0000000" & amp; A
Case 2
C="000000" & amp; A
Case 3
C="00000" & amp; A
Case 4
C="0000" & amp; A
Case 5
C="000" & amp; A
Case 6
C="00" & amp; A
Case 7
C="0" & amp; A
Case 8
C=a
In Case the Else
The Exit Function
End the Select
SP1=Mid (c, 1, 2) the number of 'head high two
SP2=Mid (c, 3, 2) the number of 'higher two
SP3=Mid (c, 5, 2) the number of 'low 2
SP4=Mid (c, 7, 2) the number of 'the lowest 2
If zijie & lt;> 1 the And zijie & lt;> 2 And zijie & lt;> 3 And zijie & lt;> 4 Then Exit Function
If mode & lt;> 0 And mode & lt;> 1 Then the Exit Function
'order mode=0 and long integer number in the same order in the content of high high byte in memory addressing low low byte in memory address
'bytes 1: Buffer (0) - sP4
'bytes 2: Buffer (0) - sP4 Buffer (1) - sP3
'bytes 3: Buffer (0) - sP4 Buffer (1) - sP3 Buffer (2) - sP2
'bytes 4: Buffer (0) - sP4 Buffer (1) - sP3 Buffer (2) - sP2 Buffer (3) - sP1
If mode=0 Then
The Select Case zijie
Case 1
Shuzu (beg)=Val (" & amp; H "& amp; SP4)
Case 2
Shuzu (beg)=Val (" & amp; H "& amp; SP4)
Shuzu (beg + 1)=Val (" & amp; H "& amp; SP3)
Case 3
Shuzu (beg)=Val (" & amp; H "& amp; SP4)
Shuzu (beg + 1)=Val (" & amp; H "& amp; SP3)
Shuzu (beg + 2)=Val (" & amp; H "& amp; SP2)
Case 4
Shuzu (beg)=Val (" & amp; H "& amp; SP4)
Shuzu (beg + 1)=Val (" & amp; H "& amp; SP3)
Shuzu (beg + 2)=Val (" & amp; H "& amp; SP2)
Shuzu (beg + 3)=Val (" & amp; H "& amp; SP1)
End the Select
End the If
'mode=1 and long integer high store content in the reverse order in a number of bytes in memory high low address byte in memory address
'bytes 1: Buffer (0) - sP4
'bytes 2: Buffer (0) - sP3 Buffer (1) - sP4
'bytes 3: Buffer (0) - sP2 Buffer (1) - sP3 Buffer (2) - sP4
'bytes 4: Buffer (0) - sP1 Buffer (1) - sP2 Buffer (2) - sP3 Buffer (3) - sP4
If mode=1 Then
The Select Case zijie
Case 1
Shuzu (beg)=Val (" & amp; H "& amp; SP4)
Case 2
Shuzu (beg)=Val (" & amp; H "& amp; SP3)
Shuzu (beg + 1)=Val (" & amp; H "& amp; SP4)
Case 3
Shuzu (beg)=Val (" & amp; H "& amp; SP2)
Shuzu (beg + 1)=Val (" & amp; H "& amp; SP3)
Shuzu (beg + 2)=Val (" & amp; H "& amp; SP4)
Case 4
Shuzu (beg)=Val (" & amp; H "& amp; SP1)
Shuzu (beg + 1)=Val (" & amp; H "& amp; SP2)
Shuzu (beg + 2)=Val (" & amp; H "& amp; SP3)
Shuzu (beg + 3)=Val (" & amp; H "& amp; SP4)
End the Select
End the If
ShutoShuzu=True
The Exit Function
Errc:
ShutoShuzu=False
MsgBox ERR. The Description
End the Function
CodePudding user response:
Code that's right, basically just write more bad,I'll according to your ideas and give you a little bit "optimization" :
'function function: turn a long integer value stored in an array
The Public Function ShutoShuzu (shu As Long, ByRef shuzu () As Byte, beg the As Byte, zijie As Byte, Optional mode As Byte=0) As Boolean
'will be a LONG value placed on a 4 byte array
On Error GoTo Errc
1 'parameters, shu to archived long integer
'2, array with shu deposited into shuzu,
'3, beg in the starting position of the array
'4, zijie stored in the array to a few bytes
'5, store mode order
Dim As a String, sP4 As String, sP3 As String, sP2 As String, sP1 As String
Dim As Byte B, c As String
ShutoShuzu=False
A=Hex (shu)
'B=Len (a)
'the Select Case B
'Case 1
'c="0000000" & amp; A
'Case 2
'c="000000" & amp; A
'Case 3
'c="00000" & amp; A
'Case 4
'c="0000" & amp; A
'Case 5
'c="000" & amp; A
'Case 6
'c="00" & amp; A
'Case 7
'c="0" & amp; A
'Case 8
'c=a
'Case Else
'the Exit Function
'to End the Select
C=Right $(" 0000000 "& amp; Hex $(shu), 8) 'only this, just like you in front of a long string of the
SP1=Mid $(c, 1, 2) the number of 'head high two
SP2=Mid $(c, 3, 2) the number of 'higher two
SP3=Mid $(c, 5, 2) the number of 'low 2
SP4=Mid $(c, 7, 2) the number of 'the lowest 2
'If zijie & lt;> 1 the And zijie & lt;> 2 And zijie & lt;> 3 And zijie & lt;> 4 Then Exit Function
If (zijie & lt; 1 the Or zijie & gt; 4) Then the Exit Function 'as far as possible to reduce the number of logical operation
'If the mode & lt;> 0 And mode & lt;> 1 Then the Exit Function
If (254) mode And Then Exit the Function 'so it is only 1 s And 0 s two situations!!!
'order mode=0 and long integer number in the same order in the content of high high byte in memory addressing low low byte in memory address
'bytes 1: Buffer (0) - sP4
'bytes 2: Buffer (0) - sP4 Buffer (1) - sP3
'bytes 3: Buffer (0) - sP4 Buffer (1) - sP3 Buffer (2) - sP2
'bytes 4: Buffer (0) - sP4 Buffer (1) - sP3 Buffer (2) - sP2 Buffer (3) - sP1
If mode=0 Then
The Select Case zijie
Case 1
Shuzu (beg)=Val (" & amp; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull