End of File doesn't seem to work 
Author Message
 End of File doesn't seem to work

I'm fairly new to this, but I'm getting an error at the end of my file, when
it doesn't seem like I shouldn't since I have a While Not EOF in there....

Any ideas?

Thanks,
Scott

PS- is it possible to Search this newsgroup?

Sub importText(strFile, rs) ' strFile is a file location and rs is a
recordset
    On Error GoTo ErrHandler
    Dim strNew As String
    Dim i As Long
    i = 0
    Open strFile For Input As #1
        Do While Not EOF(1)
            Line Input #1, strNew
            If Not strNew = "" Then
                i = i + 1
                A = Parse(strNew, ",")
                With rs
                        .AddNew
                        !ID = i
                        !YLSNetid = A(0)
                        !What = A(1)
                        !printer = A(2)
                        !Date = A(3)
                        !Time = A(4)
                        If A(11) = "" Then
                            !Pg_Count = 0
                        Else
                            !Pg_Count = A(11)
                        End If
                        !Charge = A(12)
                        !PCbalance = A(13)
                        .Update
                End With
                'If i = 10 Then Exit Sub
            End If
        Loop
Close #1
'strFile.Close    ' close the file. We're done with it!
Set strFile = Nothing

ErrHandler:
    MsgBox "An error happened here!" & vbCrLf & _
    "Error number: " & Err.Number & vbCrLf & _
    "Error Description: " & Err.Description & vbCrLf & _
    "Error Help Context ID: " & Err.HelpContext & vbCrLf & _
    "Error Help File: " & Err.HelpFile, vbCritical, "ERROR MESSAGE"

    Err.Clear ' destroy the error and.
    ' . this resumes in the last known position.
    ' in this case, since its not more than a file opening occurring,
    ' it will simply exit the function for you.
'Resume Next

End Sub



Wed, 29 Sep 2004 02:34:56 GMT  
 End of File doesn't seem to work
Hi Scott. As you've typed it, you'll always get an error message in your
code even if no error in fact occurred, because you've not inserted an Exit
Sub line before the error handler.


Quote:
> I'm fairly new to this, but I'm getting an error at the end of my file,
when
> it doesn't seem like I shouldn't since I have a While Not EOF in there....

> Any ideas?

> Thanks,
> Scott

> PS- is it possible to Search this newsgroup?

> Sub importText(strFile, rs) ' strFile is a file location and rs is a
> recordset
>     On Error GoTo ErrHandler
>     Dim strNew As String
>     Dim i As Long
>     i = 0
>     Open strFile For Input As #1
>         Do While Not EOF(1)
>             Line Input #1, strNew
>             If Not strNew = "" Then
>                 i = i + 1
>                 A = Parse(strNew, ",")
>                 With rs
>                         .AddNew
>                         !ID = i
>                         !YLSNetid = A(0)
>                         !What = A(1)
>                         !printer = A(2)
>                         !Date = A(3)
>                         !Time = A(4)
>                         If A(11) = "" Then
>                             !Pg_Count = 0
>                         Else
>                             !Pg_Count = A(11)
>                         End If
>                         !Charge = A(12)
>                         !PCbalance = A(13)
>                         .Update
>                 End With
>                 'If i = 10 Then Exit Sub
>             End If
>         Loop
> Close #1
> 'strFile.Close    ' close the file. We're done with it!
> Set strFile = Nothing

> ErrHandler:
>     MsgBox "An error happened here!" & vbCrLf & _
>     "Error number: " & Err.Number & vbCrLf & _
>     "Error Description: " & Err.Description & vbCrLf & _
>     "Error Help Context ID: " & Err.HelpContext & vbCrLf & _
>     "Error Help File: " & Err.HelpFile, vbCritical, "ERROR MESSAGE"

>     Err.Clear ' destroy the error and.
>     ' . this resumes in the last known position.
>     ' in this case, since its not more than a file opening occurring,
>     ' it will simply exit the function for you.
> 'Resume Next

> End Sub



Wed, 29 Sep 2004 03:04:44 GMT  
 End of File doesn't seem to work
Yeah, I noticed this right after posting, but my return post, didn't make it
thru....

I'm still getting a "File Already Open" error, though.  What's up with that?

Scott


Quote:
> Hi Scott. As you've typed it, you'll always get an error message in your
> code even if no error in fact occurred, because you've not inserted an
Exit
> Sub line before the error handler.



> > I'm fairly new to this, but I'm getting an error at the end of my file,
> when
> > it doesn't seem like I shouldn't since I have a While Not EOF in
there....

> > Any ideas?

> > Thanks,
> > Scott

> > PS- is it possible to Search this newsgroup?

> > Sub importText(strFile, rs) ' strFile is a file location and rs is a
> > recordset
> >     On Error GoTo ErrHandler
> >     Dim strNew As String
> >     Dim i As Long
> >     i = 0
> >     Open strFile For Input As #1
> >         Do While Not EOF(1)
> >             Line Input #1, strNew
> >             If Not strNew = "" Then
> >                 i = i + 1
> >                 A = Parse(strNew, ",")
> >                 With rs
> >                         .AddNew
> >                         !ID = i
> >                         !YLSNetid = A(0)
> >                         !What = A(1)
> >                         !printer = A(2)
> >                         !Date = A(3)
> >                         !Time = A(4)
> >                         If A(11) = "" Then
> >                             !Pg_Count = 0
> >                         Else
> >                             !Pg_Count = A(11)
> >                         End If
> >                         !Charge = A(12)
> >                         !PCbalance = A(13)
> >                         .Update
> >                 End With
> >                 'If i = 10 Then Exit Sub
> >             End If
> >         Loop
> > Close #1
> > 'strFile.Close    ' close the file. We're done with it!
> > Set strFile = Nothing

> > ErrHandler:
> >     MsgBox "An error happened here!" & vbCrLf & _
> >     "Error number: " & Err.Number & vbCrLf & _
> >     "Error Description: " & Err.Description & vbCrLf & _
> >     "Error Help Context ID: " & Err.HelpContext & vbCrLf & _
> >     "Error Help File: " & Err.HelpFile, vbCritical, "ERROR MESSAGE"

> >     Err.Clear ' destroy the error and.
> >     ' . this resumes in the last known position.
> >     ' in this case, since its not more than a file opening occurring,
> >     ' it will simply exit the function for you.
> > 'Resume Next

> > End Sub



Wed, 29 Sep 2004 03:46:22 GMT  
 End of File doesn't seem to work

Quote:

> I'm fairly new to this, but I'm getting an error at the end of my file, when
> it doesn't seem like I shouldn't since I have a While Not EOF in there....

> Any ideas?

> Thanks,
> Scott

> PS- is it possible to Search this newsgroup?

The "advanced group search" link to the right of the page will make it
easier to search just one or a few newsgroups:

 URL:http://groups.google.com/

Quote:
> Sub importText(strFile, rs) ' strFile is a file location and rs is a
> recordset

Then why are you passing strFile and rs in ByRef As Variant?

Quote:
>     On Error GoTo ErrHandler
>     Dim strNew As String
>     Dim i As Long
>     i = 0

Here you should do:

Dim fd As Integer
fd = FreeFile

Then replace those #1s with fd, because something else in your program
might also try to take over file #1.

Quote:
>     Open strFile For Input As #1
>         Do While Not EOF(1)
>             Line Input #1, strNew
>             If Not strNew = "" Then
>                 i = i + 1
>                 A = Parse(strNew, ",")
>                 With rs
>                         .AddNew
>                         !ID = i
>                         !YLSNetid = A(0)
>                         !What = A(1)
>                         !printer = A(2)
>                         !Date = A(3)
>                         !Time = A(4)
>                         If A(11) = "" Then
>                             !Pg_Count = 0
>                         Else
>                             !Pg_Count = A(11)
>                         End If
>                         !Charge = A(12)
>                         !PCbalance = A(13)
>                         .Update
>                 End With
>                 'If i = 10 Then Exit Sub
>             End If
>         Loop
> Close #1

What exactly is strFile?  If it's just a String, these next lines
would fail, since they only work on object references.

Quote:
> 'strFile.Close    ' close the file. We're done with it!
> Set strFile = Nothing

You need an Exit Sub here, or you'll always fall into the error trap.

Quote:
> ErrHandler:
>     MsgBox "An error happened here!" & vbCrLf & _
>     "Error number: " & Err.Number & vbCrLf & _
>     "Error Description: " & Err.Description & vbCrLf & _
>     "Error Help Context ID: " & Err.HelpContext & vbCrLf & _
>     "Error Help File: " & Err.HelpFile, vbCritical, "ERROR MESSAGE"

>     Err.Clear ' destroy the error and.
>     ' . this resumes in the last known position.
>     ' in this case, since its not more than a file opening occurring,
>     ' it will simply exit the function for you.
> 'Resume Next

Err gets zapped whenever you leave an error handler anyway, doesn't it?
Also, your file could still be open if you get here.  I usually wind up
maintaining some Boolean flag variables to tell me if I have files or a
transaction still open that I need to Close or Rollback before bailing
out.

Quote:
> End Sub

--
Joe Foster <mailto:jlfoster%40znet.com>  KrazyKookKultz! <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!


Wed, 29 Sep 2004 05:34:04 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. File opened for Binary read BUT instr doesn't seem to work

2. HitTest doesn't seem to work as expected

3. FormField.EntryMacro doesn't seem to work

4. AddHandler doesn't seem to work

5. AppActivate doesn't seem to work with SendKeys

6. AddHandler doesn't seem to work

7. Adding CookieCollection to WebRequest doesn't seem to work

8. close method on RegistryKey.OpenRemoteBaseKey doesn't seem to work

9. MSFlexGrid Refresh doesn't seem to work

10. Dblist doesn't seem to work correct

11. Recordset.Update doesn't seem to work

12. SavePicture doesn't seem to work with PictureBox

 

 
Powered by phpBB® Forum Software