Results 1 to 6 of 6

Thread: reading wierd characters from a file

  1. #1

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197

    reading wierd characters from a file

    Im trying to open a file that can have some really, really wierd characters. Any file open sub I try interprets those box characters as line breaks, or some other wierd thing like that. Say I had the attached zip. How could I have a sub that read the exact text?

    Make sure you read the file in notepad and compare it to what the sub reads it as
    Attached Files Attached Files
    retired member. Thanks for everything

  2. #2
    DerFarm
    Guest
    Open in Binary mode. Check out the documentation

  3. #3

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    But there is still a problem
    Attached Files Attached Files
    retired member. Thanks for everything

  4. #4
    New Member
    Join Date
    Jan 2002
    Location
    St. George, Ut
    Posts
    5

    Let's see some code

    To help you out we really need to see the code you are using. What I suspect is that you are reading the data in, but storing it in a string. Instead what you want to do is store it in a byte array.
    It is my firm conviction, that you should never have firm convictions.

  5. #5

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    I posted the code. The second attachment. I did make it a string. Ill change that later
    retired member. Thanks for everything

  6. #6
    New Member
    Join Date
    Jan 2002
    Location
    St. George, Ut
    Posts
    5

    Bad Zip File

    Every time I download test.zip, and then try to open it winzip says it is an invalid archive. Maybe you should try posting it again.

    >I did make it a string. Ill change that later

    Don't bother asking for more help on the subject until you try using byte arrays instead of strings as it is highly likely that this is the problem. Keep in mind that you need to open the file in binary mode and read the data directly into the byte array.

    Here's some sample code to read it (written off the top of my head so may contain syntax errors)

    --------------------------

    dim bytes() as byte
    dim fileNum as integer
    dim fileSize as long

    fileNum = freefile

    open "c:\testfile.test" for binary as #fileNum
    fileSize = lof(fileNum)

    redim bytes(0 to fileSize - 1)
    get #fileNum, bytes
    close #fileNum

    ---------------------------------

    That will read in your file. Keep in mind, though that if you take the data in your byte array then shove it into a string it will still mess up the data, because the characters that are causing the problems are still there. You will have to perform all operations on your data from the byte array, and write it back out with the byte array.

    One thing that might help for future posts is if you tell us what you want to do with the data once you've read it in.
    It is my firm conviction, that you should never have firm convictions.

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