Home > Software engineering >  Please use VBA to tongda letter block_gn. Dat conversion to form code
Please use VBA to tongda letter block_gn. Dat conversion to form code

Time:11-15

Tongda letter block_gn. Dat file for the concept of plates, as A binary file structure, the first 384 bytes for the header, need not take, beginning from 386 bytes, each plate occupy 2813 bytes, the top 8 bytes for name plate, after the 2800 bytes to include stock code, just take the two portions, respectively in A, B two columns, has completed ChengBu code, transformation part haven't finished, please help,

Completed part code is as follows:
Filename=ThisWorkbook. Path & amp; "\ block_gn. Dat"
The Open Filename For Binary As # 1 'to Open the file read-only way, refer to the help of the Open method
FileLen=LOF (1) - 386
ReDim FileByte (FileLen) As Byte
Get # 1, 387, FileByte () '386th (0) at the beginning start plate information, each point of 2813 bytes, started the second plate to 3199 bytes
Close # 1

ReDim FileStr (FileLen) As String
For I=1 To FileLen
J=I Mod 2813 'take each plate record number
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
O buffering part
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
If j=0 then
Sheet1. Cells (Int (I/2813) + 2, 1)=bkname 'plate name
Sheet1. Cells (Int (I/2813) + 2, 2)=gpcode contains stock code
'Bkname=""
Gpcode=""
End the if
Next I

CodePudding user response:

In the way of thinking, their success solve
Private Declare Sub CopyMemory Lib "kernel32. DLL" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)

FileByte Call CopyMemory (bkName (0), (I - 1) * (2813), 8)
FileByte Call CopyMemory (gpCode (0), ((I - 1) * 2813 + 13), 2800)
BK=StrConv (bkName vbUnicode)
GP=StrConv (gpCode vbUnicode)
  •  Tags:  
  • VBA
  • Related