Results 1 to 8 of 8

Thread: How to write a file in VB6.0 and read it in VB.net

Threaded View

  1. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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:
    1. Dim filelength As FileInfo
    2.         Dim r As Int64
    3.         filelength = New FileInfo("C:\testfile.tst") 'get the filelength
    4.         r = filelength.Length
    5.         'each long in vb6 is 4 bytes, so length of file / 4 is how many
    6.         'longs were stored
    7.  
    8.         'loop counter
    9.         Dim i As Integer
    10.  
    11.         'create a binaryreader to the file
    12.         Dim BR As New IO.BinaryReader(IO.File.OpenRead("C:\testfile.tst"))
    13.         'create a int32 (comparable to vb6 long) array
    14.         Dim h() As Byte
    15.         'redimension to size of file elements
    16.         ReDim h(r)
    17.  
    18.         h = BR.ReadBytes(r)
    19.         Debug.Write(CStr(r))
    20.         MsgBox("done")
    Last edited by nemaroller; Oct 21st, 2002 at 02:45 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width