Results 1 to 11 of 11

Thread: how to read any file

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    36

    how to read any file

    hello everybody

    i try to read a file with input function but it works only with files that contains regular characters

    if i want to read a mid file with this code:

    VB Code:
    1. Dim filetext, filename As String
    2. filename = Dlg.filename
    3. Open filename For Input As #1
    4.     filetext = Input(LOF(1), #1)
    5. Close #1

    It give error: input past end of file
    why?

  2. #2
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: how to read any file

    The error means its treating one of the unknown characters as an End of File pointer... But, the end of the file hasn't been reached according to the total length.

    Common error. Not worked out how to get round it yet though.
    Zeegnahtuer?

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    36

    Re: how to read any file

    excuse me i'm italian there is or not a solution?

    i could try with file system object

  4. #4
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: how to read any file

    Wait for the more experienced members around here to give you a hand, i can't think of an easier or better way to handle displaying a file with unknown characters.
    But, maybe they can
    Zeegnahtuer?

  5. #5
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: how to read any file

    work around,


    VB Code:
    1. Dim filetext As String
    2. Dim filename As String
    3. Dim sBuff    As String
    4.  
    5.     filename = Dlg.filename
    6.     Open filename For Input As #1
    7.     Do While Not EOF(1)
    8.         Line Input #1, filetext
    9.         sBuff = sBuff & vbNewLine & filetext
    10.         Close #1
    11.     Loop

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    36

    Re: how to read any file

    it work only with text files because when i view the lenght of sBuff, it is different from lenght of file.
    the variable was trimmed.

    it doesn't show all characters

    for ex:
    the file was 91440 characters
    in the sBuff there are 6163 characters

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: how to read any file

    I forget who posted this, but it should solve the problem.
    Attached Files Attached Files

  8. #8
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: how to read any file

    I would try reading in the binary mode.
    For instruction on how to do this, please see the tutorial on my site. On this page:
    http://www.thevbprogrammer.com/tutorials.html
    Check out "Binary Files" under "6. Files".
    "It's cold gin time again ..."

    Check out my website here.

  9. #9
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: how to read any file

    also have a look at my sig for thw api method.

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    36

    Re: how to read any file

    i've tryed also that program "read buffer" but it doesn't work

    i want to retrive every single charaters from a Midi files.

    before i had vb.net but i've lost it
    in vb.net reading working.

  11. #11
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: how to read any file

    MIDI files are binary. That's the only way to read them.

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