Hi,

What's wrong with my code - which is designed to count the number of lines in long ascii files and gives the user a chance to abort the process:



HTML Code:
        int_current_file_number = FreeFile
        cmdCount.Visible = False
        cmdStop.Visible = True
    
        
         Open lstrFileName$ For Input As int_current_file_number
             
             Do While EOF(int_current_file_number) = False
                Line Input #int_current_file_number, str_input ' input file in str_input to count lines
                lngNumberLines = lngNumberLines + 1 ' increment lines
                If lngNumberLines Mod 1000 = 0 Then ' return focus to system every 1000 lines, update count
                    DoEvents
                    lblLines = "(total: " & lngNumberLines & ")"
                End If
                If blnAbort = True Then ' if user clicked stop then clear count and show count command button
                    lblLines.Caption = "(total: Unknown)"
                    cmdCount.Visible = True
                    cmdStop.Visible = False
                    Exit Do
                End If
             Loop
             
           
        Close int_current_file_number



If I click the 'cmdstop' button somehow the int_current_file_number is incremented by one and the do...loop continues and produces a 'bad file number error'. The sub isnt revisiting the first line of code again (I used breakpoints) so how is it incrementing....??

No doubt it is some simple oversight but I just can't figure it out. Thanks for your time.

Cheers,
Vbnewbie