Home >
Software engineering > To perform here to cross-border -- -- -- -- -- "Length (I)=HEX_to_DEC (Mid (ParaStr (I), 1, 2))
To perform here to cross-border -- -- -- -- -- "Length (I)=HEX_to_DEC (Mid (ParaStr (I), 1, 2))
Private Sub cmdConvert_Click ()
Dim strBinFileName As String
'to prevent code reentrant
CmdConvert. Enabled=False
Effective
'to determine whether a file pathDo
If Dir (Trim (txtHexFileName. Text))="" Or Trim (txtHexFileName. Text)=" "Then
'the user is not choose the files, simulated users click the TextBox produce event
TxtHexFileName_Click
The Else
The Exit Do
End the If
Loop
StrBinFileName=Trim (txtHexFileName. Text)
StrBinFileName=Left (strBinFileName, Len (strBinFileName) - (4) 'remove extension
StrBinFileName=strBinFileName + "bin"
If Hex_To_Bin_Convert (txtHexFileName. Text, strBinFileName, ProgressBar1)=False Then
'the operation failure
MsgBox "format conversion failed!" , vbCritical, "error"
The Else
'operation success
MsgBox "format conversion success!" + CRH (13) + CRH (10) + strBinFileName + ", "vbInformation," tip "
End the If
'open button function
CmdConvert. Enabled=True
End Sub
Private Sub Form_Load ()
With ProgressBar1
. Top=frmMain. TxtHexFileName. Top + 20
. Left=frmMain. TxtHexFileName. Left + 20
. Height=frmMain. TxtHexFileName. Height - 30
. Width=frmMain. TxtHexFileName. Width - 30
The Visible=False
End With
End Sub
Private Sub txtHexFileName_Click ()
On Error GoTo Err_Handle:
CommonDlg. DialogTitle="Open File"
CommonDlg. Flags=cdlOFNCreatePrompt Or cdlOFNReadOnly
CommonDlg. CancelError=True
CommonDlg. Filter="Intel Hex File (*. Hex) | *. Hex"
CommonDlg. ShowOpen
TxtHexFileName. Text=CommonDlg. FileName
The Exit Sub
Err_Handle:
Err. Clear
End Sub
The Public Function Hex_To_Bin_Convert _
(_
StrHEXFileName As String, _
StrBinFileName As String, _
Progress As ProgressBar _
) As a Boolean
Dim StringLine As String
Dim StringLine1 As String
Dim dwFileLength As Long
Dim Start_address () As Long
Dim Length () As Long
Dim dwSize As Long
Dim RecordType As Integer
Dim wAddress As Long
Dim wWriteAddress As Long
Dim Address () As String
Dim n As Long
Dim As Long I 'temporary variable
Dim Hexfile_RowCount As Long 'Hex file number of rows
Dim chData As Byte
Dim ParaStr () As String 'reads the parameter array
Dim ParaStr1 () As String 'reads the parameter array
Dim Data_FF As String 'reads the parameter array
Dim the Data () As String 'reads the parameter array
Hex_To_Bin_Convert=False
ChData=https://bbs.csdn.net/topics/&HFF
StrBinFileName=Trim (strBinFileName)
With the Progress
The Enabled=True
The Value=https://bbs.csdn.net/topics/0
The Visible=True
Data_FF="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
'open source file Hex
The Open strHEXFileName For Input As # 1
'get the length of the HEX file
DwFileLength=FileLen (strHEXFileName)
'reads a record from HEX file
The Line Input # 1, StringLine
'Hexfile_RowCount=UBound (Split (StringLine vbCr))
'Hexfile_RowCount=UBound (Split (StringLine, vbCrlf))
Hexfile_RowCount=UBound (Split (StringLine vbLf))
StringLine1=Right (StringLine dwFileLength - 1)
'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data processing -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -'
ParaStr=Split (StringLine1, ":")
For I=0 To (Hexfile_RowCount - 3)
Length (I)=HEX_to_DEC (Mid (ParaStr (I), 1, 2))
'Start_address (I)=HEX_to_DEC (" & amp; H "& amp; Mid (ParaStr (I), 7, 2))
'Address (I)=Mid (ParaStr (I), 3, 4)
Next
For I=0 To (Hexfile_RowCount - 3)
If Start_address (I)=0 Then
If Length (I) * 2=32 Then
00 'starting address length data of 16 78340034 c2340034b834023478340034
Data (I)=Mid (ParaStr (I), 9, Length (I) * 2)
00 'starting address length 4 fill 12 FF
'0 c 94 CD 01 FF FF FF FF FF FF FF FF FF FF FF FF after fill 12 FF
The Else
'Data (I)=Mid (ParaStr (I), 9, Length (I) * 2) & amp; Mid (Data_FF, Length (I) * 2 + 1, (16 - Length (I)) * 2)
End the If
The Else
'the starting address not 00 length 4
'FF FF FF FF FF FF FF FF FF FF FF FF 0 c 94 3 e 05 fill 12 FF before
'Data (I)=Mid (Data_FF, Length (I) * 2 + 1, (16 - Length (I)) * 2) & amp; Mid (ParaStr (I), 9, Length (I) * 2)
End the If
Next
Close # 1
The Enabled=False
The Visible=False
End With
End the Function
The Public Function HEX_to_DEC (ByVal Hex As String)
Dim As Long I
Dim As Long B
Hex=UCase (Hex)
For I=1 To Len (Hex)
Select Case mids (Hex, Len (Hex) - I + 1, 1)
A Case of "0" :
B=B + 16 ^ (I - 1) * 0
A Case of "1" :
B=B + 16 ^ (I - 1) * 1
Case "2" :
B=B + 16 ^ (I - 1) * 2
Case "3" :
B=B + 16 ^ (I - 1) * 3
A Case of "4" :
B=B + 16 ^ (I - 1) * 4
Case "5" :
B=B + 16 ^ (I - 1) * 5
A Case of "6" :
B=B + 16 ^ (I - 1) * 6
A Case of "7" :
B=B + 16 ^ (I - 1) * 7
Case "eight" :
B=B + 16 ^ (I - 1) * 8
"9" Case:
B=B + 16 ^ (I - 1) * 9
Case "A" :
B=B + 16 ^ (I - 1) * 10
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull