|
-
Dec 15th, 2006, 05:23 AM
#1
Thread Starter
Frenzied Member
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 ....
-
Dec 15th, 2006, 10:18 AM
#2
Addicted Member
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 
-
Dec 15th, 2006, 10:26 AM
#3
Thread Starter
Frenzied Member
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.
-
Dec 15th, 2006, 10:57 AM
#4
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
-
Dec 15th, 2006, 10:58 AM
#5
Thread Starter
Frenzied Member
Re: Reading text files and checking for corruption
Yeah thats what I was afraid of !
-
Dec 15th, 2006, 05:45 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|