-
I thought I'd make a quick utility for myself to extract all ASCII "printable" characters from a file, but unfortunately, this code causes my app to hang when I run it. Can you tell me where I went wrong? (BTW, this is just a quickie, don't yell at me for lack of naming conventions and error handling!)
Code:
' in a command button
Dim lnglen As Long
Dim strchar As String * 1
Dim lngX As Long
Dim intFF As Integer
CommonDialog1.ShowOpen
intFF = FreeFile
Open CommonDialog1.filename For Binary Access Read As #intFF
lnglen = LOF(intFF)
For lngX = 1 To lnglen
Get #intFF, lngX, strchar
If Asc(strchar) >= 32 And Asc(strchar) <= 127 Then
Text1.Text = Text1.Text & strchar
End If
Next
Close #intFF
TIA for your help ...
-
<?>
'try this
'looks like you keep reading the full line over and over
'just a guess..didn't test this
Dim lnglen As Long
Dim strchar As String * 1
Dim lngX As Long
Dim intFF As Integer
CommonDialog1.ShowOpen
intFF = FreeFile
Open CommonDialog1.FileName For Binary Access Read As #intFF
lnglen = LOF(intFF)
For lngX = 1 To lnglen
Get #intFF, lngX, strchar
If Asc(strchar) >= 32 And Asc(strchar) <= 127 Then
Text1.Text = Text1.Text & strchar
End If
strchr = Right(strchr, lnglen - 1)
Next
Close #intFF
-
it would be better to read a chunk of the data into a buffer string and parse in RAM instead of pulling one byte at a time from the file. This way you can read a buffers worth of data, pull out what you need and repeat until you are done with the file.