I am reading a list of files from a listbox and then printing each one. I added some error handling to handle missing files, which will continue with the next file to print. However, I am not very clear with the error handling of VB and it seems my code can be improved.
Soemtimes, when there is a error (listbox is empty), if I press Print again, there is a error "For loop not initialised". I know it has to do the 'nextF' statement but I am not sure how to improve/ correct it.
I provided main parts of my print function...
sorry, I don't have much points left... :(
Thanks a lot!
Private Sub Print_Click()
On Error GoTo handleErr
For i = 0 To (List1.ListCount - 1) ' read from list1
On Error Resume Next
Open (list1.text) For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
' print line
' close file
End If ' response = vbyes
Exit Sub 'avoid error handler
Select Case Err.Number ' Evaluate error number.
Case 32755 ' printer error
MsgBox ("Error printing. Printing aborted.")
Case 53: ' file not found
MsgBox ("File " & ToPrint & " not found. Continuing with next file.")