My bane (among other VB things) - error handling.
I have code that parses lines of text, one line at a time, and inserts the results into a database. I don't know if I am doiung the best and most efficient way, but it works. Generally,
Dim objLine As TextStream
Dim strNewLine As String
Set objLine = fs
penTextFile(textfile, ForReading, , TristateFalse)
Do While Not objLine.AtEndOfStream
process text fields
Loop
In the 'process text fields', I process each field individually. There are 15-25 fields, depending on the text file. Should I encounter an error anywhere during the processing of the line, I want inform the user (I plan to add it to a log file), stop processing the current record and go to the next record.
I have On Error Goto ErrHndl at the beginning of the sub. The handler is outside the loop, and it lets the user know an error was encountered and returns to inside the loop near the "Loop" statement to do some cleanup before processing the next record.
I think this is bad, bad programming on my part, since it seems like I am jumping out of a loop then back in (and I have yet to test the consequences). On Error Resume Next does not seem feasible without adding code after processing each field. How does one handle an error inside a loop, yet continue processing after handling the error?
Jim
I have code that parses lines of text, one line at a time, and inserts the results into a database. I don't know if I am doiung the best and most efficient way, but it works. Generally,
Dim objLine As TextStream
Dim strNewLine As String
Set objLine = fs
Do While Not objLine.AtEndOfStream
process text fields
Loop
In the 'process text fields', I process each field individually. There are 15-25 fields, depending on the text file. Should I encounter an error anywhere during the processing of the line, I want inform the user (I plan to add it to a log file), stop processing the current record and go to the next record.
I have On Error Goto ErrHndl at the beginning of the sub. The handler is outside the loop, and it lets the user know an error was encountered and returns to inside the loop near the "Loop" statement to do some cleanup before processing the next record.
I think this is bad, bad programming on my part, since it seems like I am jumping out of a loop then back in (and I have yet to test the consequences). On Error Resume Next does not seem feasible without adding code after processing each field. How does one handle an error inside a loop, yet continue processing after handling the error?
Jim