Speeding up the importing of data from file

F

Fan924

I am using the following to import binary data from a file and convert
to hexadecimal. Is there a different way to do this that would be
faster? I got list help last year to speed up my checksum routine by
putting the data into a variant array. I was able to also us it for
saving to a file too. I need some of the same magic importing data
from a file. File size can be over a meg in size and is taking minutes
to load.
_____________________________________________________

Dim fs, f, ts, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(FileNameWithPath)
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
ColumnCount = 3
RowCount = 1
Do While ts.atendofstream = False 'Loop to fill column with HEX
numbers
DecimalByte = Asc(ts.Read(1))
HexByte = Hex(DecimalByte)
Cells(RowCount, ColumnCount) = HexByte
RowCount = RowCount + 1
Loop
ts.Close
 
B

Barb Reinhardt

I'd add this at the beginning of code

Application.ScreenUpdating = false
Application.calculation = XLCalculationManual

and at the end

Application.ScreenUpdating = True
Application.Calculation = xlcalculationAutomatic
 
G

geoff_ness

I am using the following to import binary data from a file and convert
to hexadecimal. Is there a different way to do this that would be
faster?  I got list help last year to speed up my checksum routine by
putting the data into a variant array. I was able to also us it for
saving to a file too. I need some of the same magic importing data
from a file. File size can be over a meg in size and is taking minutes
to load.
_____________________________________________________

Dim fs, f, ts, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(FileNameWithPath)
    Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
    ColumnCount = 3
    RowCount = 1
Do While ts.atendofstream = False 'Loop to fill column with HEX
numbers
    DecimalByte = Asc(ts.Read(1))
    HexByte = Hex(DecimalByte)
    Cells(RowCount, ColumnCount) = HexByte
    RowCount = RowCount + 1
Loop
ts.Close

I would change the way you're returning results to the spreadsheet.
Try populating an array in the loop, and then transferring values all
at once at the end rather than a cell at a time - this is likely to be
a lot faster. Reading the file into the textstream does not take that
long, even for a file of the size you're dealing with - I timed
something similar in Python at around 18 seconds for 100 iterations to
read a 250KB pdf, convert byte-by-byte to ansi code, then hex, then
return to an array. VBScript is a bit slower perhaps, but certainly
with Excel transferring data to the worksheet is the more likely place
for a bottleneck to occur.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top