Results 1 to 11 of 11

Thread: Reading a text file wrong....

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Reading a text file wrong....

    Sorry for the bad gode I have posted, but this is just a test. I am going to read a text file and splitt it up into an array, but something is wrong with the file reading...it skipps a lot of spaces. Open the text tile in notepad to see how it should be...



    Cut and paste link:
    http://www.geocities.com/note_ladybug/word.zip

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    From that link I get:

    We're sorry, but this page is currently unavailable for viewing.

    If this site belongs to you, please read this help page for more information and assistance.

    For general questions see our main help area, or search for other member pages.
    Try attaching it instead?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Sorry to big...nearly 200k....did you cut and paste the link Hobo?

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by NoteMe
    Sorry to big...nearly 200k....did you cut and paste the link Hobo?
    No...why is it so big?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    It was a dictionary that is 1Mb zipped down to 100k + the app... myabe I can cheat and post it in two posts?

  6. #6

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    OK..now I think it is working...try the link...

    http://www.geocities.com/note_ladybug/word.zip

  7. #7
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    The link wasn't properly cased, here's the correct one: http://www.geocities.com/note_LadyBug/word.zip

    The problem is, the file contains null characters (Chr(0)), resulting in the data being cut off.

    When you open this in Notepad, it converts them to spaces, I suggest you do the same thing.

  8. #8

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Thanks there....

    but will I have to read the file first into a string, then replace all teh (Chr(0)) with spaces, and then print out?

  9. #9

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    OK...what do you actuall mean now?

    VB Code:
    1. Buffer = Replace(Buffer, Chr(0), " ")
    ??

  10. #10
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You need to convert them to spaces prior to splitting it into an
    array or anything else that might interpret the null charcters as
    the end of the line/string.

    VB Code:
    1. Public Function fnFileToStr(ByVal sFile As String) As String
    2.   Dim iFile As Integer
    3.   Dim sBuffer As String
    4.  
    5.   iFile = FreeFile
    6.   Open sFile For Binary Access Read As iFile
    7.     sBuffer = Space(LOF(iFile))
    8.     Get #iFile, , sBuffer
    9.   Close iFile
    10.   fnFileToStr = sBuffer
    11. End Function
    Example:
    VB Code:
    1. sString = Replace(fnFileToStr("eng_nor.wb"), chr(0), " ")

  11. #11

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Thanks Aaron Young, you are todays saver....it didn't help with just using the replace function as in my last post. So I tried binary reading as in your post, and everything worked as it should. I think that if I use the other way of reading the text file it just converts the chr(0) to "" automaticaly when it read the text. So again thanks....

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