Why does this hang up?

F

Fan924

Why does this hang up? It works on 16k files. Not on 32k and above. It
loads about 200 lines and then seems go get stuck in a loop.

Dim FileType As String
If FileType = "bin" Then
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(FileName)
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
ColumnCount = 3
RowCount = 2
Do While ts.atendofstream = False
Hexbyte = Asc(ts.Read(1))
Cells(RowCount, ColumnCount) = Hex(Hexbyte)
RowCount = RowCount + 1
Loop
ts.Close
MsgBox "bin"
Else
End If
End Sub
 
S

SeanC UK

Hi Fan,

I have tried the code and it is working well up to 64k (over which you start
hitting the row limit at 65536).

I am assuming that the 200 lines you refer to are in the original file (not
200 rows = 200 character reads). If you know roughly how many characters this
is when it gets stuck, then add a Watch so that the code breaks when RowCount
is just before this value and step through the code using F8 to see if you
can see why it is getting stuck.

Alternatively, try using the ReadLine method to obtain one line at a time,
and then write some code to take each character from that line one at a time.

A difference in these two approaches is that the Read method will include
the Carriage Return and Line Feed characters at the end of each line, and
will add them to your Excel file, whereas the ReadLine method uses these to
determine the end of each line, and therefore will not add them to your Excel
file.

You can also try using the ReadAll method, that way you can get all the data
in one go and see if you still get the problem. This is far from an ideal
solution, and there will be limits on the length of String length you read,
although 32k should be OK. Again, you would have to write the extra code to
step through each character in the string that is returned.

In any case I don't see why your code shouldn't be working though. There
appears to be nothing that would put it in an endless loop. Stepping through
the code would enable you to check this (F8). It might be that something is
hanging rather than being stuck in a loop?

If you have any more information then let me know and I'll see if I can me
of more help.

Sean.
 
F

Fan924

Thanks Joel but it was a false alarm. I went to try your suggestion
and found it was working again before any changes. I reloaded windows
today. That was the problem. I made the change to "Dim RowCount as
Long" anyway because it was a good idea.
 
F

Fan924

Hi Fan,

I have tried the code and it is working well up to 64k (over which you start
hitting the row limit at 65536).

I am assuming that the 200 lines you refer to are in the original file (not
200 rows = 200 character reads). If you know roughly how many characters this
is when it gets stuck, then add a Watch so that the code breaks when RowCount
is just before this value and step through the code using F8 to see if you
can see why it is getting stuck.

Alternatively, try using the ReadLine method to obtain one line at a time,
and then write some code to take each character from that line one at a time.

A difference in these two approaches is that the Read method will include
the Carriage Return and Line Feed characters at the end of each line, and
will add them to your Excel file, whereas the ReadLine method uses these to
determine the end of each line, and therefore will not add them to your Excel
file.

You can also try using the ReadAll method, that way you can get all the data
in one go and see if you still get the problem. This is far from an ideal
solution, and there will be limits on the length of String length you read,
although 32k should be OK. Again, you would have to write the extra code to
step through each character in the string that is returned.

In any case I don't see why your code shouldn't be working though. There
appears to be nothing that would put it in an endless loop. Stepping through
the code would enable you to check this (F8). It might be that something is
hanging rather than being stuck in a loop?

If you have any more information then let me know and I'll see if I can me
of more help.

Sean.






- Show quoted text -
 
F

Fan924

My last message vanished. Not my day. The problem returned. It is not
stopping but slowing. 4000 hex bits input to column C takes 42
seconds. There are a total of 32,000 hex bits (row) total. Not wvwn
the Z80 was that slow. I want to rewrite it without the tristate
stuff. I don't really understand it. It was an example by another
member here.
 
F

Fan924

Hi Sean, The problem is back. It does not actually stop. It slows down
to a crawl. 4000 rows of 32,000 rowse takes 42 seconds.
Sloooooooooooooooowww!

I think I have to replace the tristate code that I really do not
understand. It was from an example someone gave me.
 

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