Results 1 to 6 of 6

Thread: Reading text files and checking for corruption

  1. #1

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Question Reading text files and checking for corruption

    Morning all !

    I'm writing a program that reads x amount of text files.
    Each file has a header record, a bunch of detail records and then a footer record.

    Due to the nature of these files it is possible that some can be corrupted.
    Problem is they could be corrupted anywhere within the file.

    Now ... I can code this with loads of IF THEN statements as I pluck each field out from each row, but I know there must be a neater way of checking them record by record, probably using a routine of some kind.

    Has anyone out there done anything similar ? I'm just looking for a "neat" a way as possible really, rather than my old archaic way of doing things.

    Thanks ....

  2. #2
    Addicted Member
    Join Date
    Oct 2004
    Location
    Clane, Ireland
    Posts
    179

    Re: Reading text files and checking for corruption

    What do you mean by corrupt? Not the right length, not the correct number of records as per header / footer, incorrect total as per header / footer?
    JP

    Please rate the postings

  3. #3

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Re: Reading text files and checking for corruption

    No the record data can contain "rogue characters" or spaces where it shouldn't.
    Basically the format gets right of step.
    Normally happens in the middle of the file, but has the potential to happen anywhere.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Reading text files and checking for corruption

    You'd have to parse each field or each record (depending on the actual file format). You could do it in a loop to save code, but there's no TextIsCorrupt() function or anything like that. Depending on what "rogue character" means, and whether spaces are allowed in some places but not others, or just not allowed, the code could be simple or it could be complex. (Whichever, it's going to be slow if you implement it in VB.)
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  5. #5

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Re: Reading text files and checking for corruption

    Yeah thats what I was afraid of !

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Reading text files and checking for corruption

    if it gives an error when your program gets to a corruption in the data, you can just put error handling to do whatever is required to fix when an error happens
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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