Alex_rcpilot
Member
Hi guys.I'm trying to write a program which is kind of like a simple Flash memory programmer.I can read the *.BIN file into an array of byte buffer variables.And I can display the content of the BIN file in a text box.But the process is really slow and it even freezes the entire PC.What I did first is assigning each byte the respective value read from the file.Just like the last segment of the code listed down there.This process takes about 3 seconds to open a file with a size of 261KB,and the computer freezes during this period.
To display the content I used samilar structure as this:
TextName.Text = TextName.Text & .......
and the computer freezes a lot longer before the result comes out.
I'm working on hardware most of the time so Visual Basic isn't really familiar to me.I bet I chose the worst way to preview the BIN file. :? Could someone here show me some better ways?Thank you in advance!
Regards,Alex
'===============
Dim i As Long
Dim Lib() As Byte
Dim Buf() As String
Dim Ptr As Long
Dim Lp As Integer
'---------------
'Open file
Path.Action = 1
Open Path.FileName For Binary Access Read As #1
'---------------
'Redefination
i = LOF(1) 'FileLen(Path.FileName)
ReDim Lib(i) As Byte
ReDim Buf(i) As String
'---------------
'Display file information
TextName.Text = "File Path: " & Path.FileName & Chr(13) + Chr(10)
TextName.Text = TextName.Text & "File Length: " & i & "Bytes"
TextName.Text = TextName.Text & " (" & CInt(i / 1024) & "KB)" & Chr(13) + Chr(10) & Chr(13) + Chr(10)
'---------------
'Read file into buffer
Ptr = 1 'Attention:Starting index = 1 rather than 0x0 in MC systems.
For Ptr = 1 To i
Get #1, Ptr, Lib(Ptr)
Buf(Ptr) = Hex(CInt(Lib(Ptr))) & "H "
If Lib(Ptr) < 16 Then
Buf(Ptr) = "0" & Buf(Ptr)
End If
Next Ptr
Close #1
'---------------
To display the content I used samilar structure as this:
TextName.Text = TextName.Text & .......
and the computer freezes a lot longer before the result comes out.
I'm working on hardware most of the time so Visual Basic isn't really familiar to me.I bet I chose the worst way to preview the BIN file. :? Could someone here show me some better ways?Thank you in advance!
Regards,Alex
'===============
Dim i As Long
Dim Lib() As Byte
Dim Buf() As String
Dim Ptr As Long
Dim Lp As Integer
'---------------
'Open file
Path.Action = 1
Open Path.FileName For Binary Access Read As #1
'---------------
'Redefination
i = LOF(1) 'FileLen(Path.FileName)
ReDim Lib(i) As Byte
ReDim Buf(i) As String
'---------------
'Display file information
TextName.Text = "File Path: " & Path.FileName & Chr(13) + Chr(10)
TextName.Text = TextName.Text & "File Length: " & i & "Bytes"
TextName.Text = TextName.Text & " (" & CInt(i / 1024) & "KB)" & Chr(13) + Chr(10) & Chr(13) + Chr(10)
'---------------
'Read file into buffer
Ptr = 1 'Attention:Starting index = 1 rather than 0x0 in MC systems.
For Ptr = 1 To i
Get #1, Ptr, Lib(Ptr)
Buf(Ptr) = Hex(CInt(Lib(Ptr))) & "H "
If Lib(Ptr) < 16 Then
Buf(Ptr) = "0" & Buf(Ptr)
End If
Next Ptr
Close #1
'---------------