Obviously my code runs slow because on each looped read
1) its converting a Long into a String
2) writing that value to the debug window
If you comment out the debug.writeline method, it will run tremendously faster... I put that line in so you could see it works...
However, you can read all the bytes at once... using .ReadBytes method of the BinaryReader class.... and skip the for loop.
But, you will now have a byte array of bytes, where each 4 bytes represents one Long.... so you then have to feed that byte array into a function which converts it... like I said before, you can check the Internet using google for a function to do that.. or you can write it yourself...but it will undoubtedly be slower than ReadInt32 method of the BinaryReader
VB Code:
Dim filelength As FileInfo Dim r As Int64 filelength = New FileInfo("C:\testfile.tst") 'get the filelength r = filelength.Length 'each long in vb6 is 4 bytes, so length of file / 4 is how many 'longs were stored 'loop counter Dim i As Integer 'create a binaryreader to the file Dim BR As New IO.BinaryReader(IO.File.OpenRead("C:\testfile.tst")) 'create a int32 (comparable to vb6 long) array Dim h() As Byte 'redimension to size of file elements ReDim h(r) h = BR.ReadBytes(r) Debug.Write(CStr(r)) MsgBox("done")




Reply With Quote