Results 1 to 14 of 14

Thread: [RESOLVED] Error past end of file

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [RESOLVED] Error past end of file

    I have a Function that tracks uses of my program and every once in a while
    I get an error Error #62 Input past end of file. It seems a value is not written to the file in some cases and the error occurs because the file is empty. Why does a value not get written to the in the FirstLoad part of the function ?

    Code:
    Function Countit()
              Dim fnumber As Integer
              Dim fNumber2 As Integer          
              Dim File1 As String
              Dim File2 As String
              Dim Value1 As String
              Dim Value2 As String
              
              Dim Count1 As String
              Dim Count2 As String         
       On Error Goto e
           File1 = gPathWithOutFolder & "\xpW32vst.syv"'path set in sub main
           File2 = gPathWithOutFolder & "\xpW32sys.xyp"
        
            fnumber = FreeFile()  
    
    
    80         If FileExists(File1) Then
    90            Open File1 For Input As #fnumber
                    ' Debug.Print FileLen(File1)
                  'If FileLen(File1) <> 0 Then
    100           Line Input #fnumber, Value1 'error here on some systems
    110                'Debug.Print File1
    120               Close #fnumber
    
    130          Else
    140           GoTo FirstLoad
                 ' End If '
    150        End If
    
    
        
    
    FirstLoad:
    510       Open File1 For Output As #fnumber
    520        Count1 = 1
    530        Print #fnumber, Count1
    540       Close #fnumber
              
    550       Open File2 For Output As #fnumber
    560        Count2 = 1
    570        Print #fnumber, Count2
    580       Close #fnumber
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Error past end of file

    Try this instead:
    Code:
    Open File1 For Input As #fnumber
        Do While Not Eof(fnumber)
            Line Input #fnumber, Value1
            'do something with Value1 here
        Loop
    Close #fnumber

  3. #3

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Error past end of file

    Quote Originally Posted by RhinoBull View Post
    Try this instead:
    Code:
    Open File1 For Input As #fnumber
        Do While Not Eof(fnumber)
            Line Input #fnumber, Value1
        Loop
    Close #fnumber
    Thanks for the reply, your method looks better than mine for checking:
    If FileExists(File1) And FileLen(File1) > 0 Then

    However I am more concerned with how the file could be empty. The first time a user runs my app it does not exist. I have changed the Firstload file handling to
    fnumber2 = FreeFile()
    Open File2 For Output As #fnumber2
    Count2 = 1
    Print #fnumber2, Count2
    Close #fnumber2
    This error happens so seldom and i have been able to recreate it, now i can only wait
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Error past end of file

    Reasons for failure? Many, including permissions, path doesn't exist, out of disk space, bad sector maybe, and several more. Error checking should be applied. If the file fails to write, should be getting an error, no?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Error past end of file

    Quote Originally Posted by isnoend07 View Post
    I have a Function that tracks uses of my program and every once in a while
    I get an error Error #62 Input past end of file. It seems a value is not written to the file in some cases and the error occurs because the file is empty. Why does a value not get written to the in the FirstLoad part of the function ?

    Code:
    Function Countit()
              Dim fnumber As Integer
              Dim fNumber2 As Integer          
              Dim File1 As String
              Dim File2 As String
              Dim Value1 As String
              Dim Value2 As String
              
              Dim Count1 As String
              Dim Count2 As String         
       On Error Goto e
           File1 = gPathWithOutFolder & "\xpW32vst.syv"'path set in sub main
           File2 = gPathWithOutFolder & "\xpW32sys.xyp"
        
            fnumber = FreeFile()  
    
    
    80         If FileExists(File1) Then
    90            Open File1 For Input As #fnumber
                    ' Debug.Print FileLen(File1)
                  'If FileLen(File1) <> 0 Then
    100           Line Input #fnumber, Value1 'error here on some systems
    110                'Debug.Print File1
    120               Close #fnumber
    
    130          Else
    140           GoTo FirstLoad
                 ' End If '
    150        End If
    
    
        
    
    FirstLoad:
    510       Open File1 For Output As #fnumber
    520        Count1 = 1
    530        Print #fnumber, Count1
    540       Close #fnumber
              
    550       Open File2 For Output As #fnumber
    560        Count2 = 1
    570        Print #fnumber, Count2
    580       Close #fnumber
    I'm not exactly sure what your code looks like now but in the above code you don't need (and shouldn't have) the GoTo FirstLoad line and the FirstLoad label.

  6. #6

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Error past end of file

    Quote Originally Posted by LaVolpe View Post
    Reasons for failure? Many, including permissions, path doesn't exist, out of disk space, bad sector maybe, and several more. Error checking should be applied. If the file fails to write, should be getting an error, no?
    Thanks for the reply
    yes it gets an error: "Endput past end of file" and upon testing i have determined the file is created, but is empty.
    permissions & path is not the problem as other files are written before this function to the same folder location.
    bad sector and out of disk space would be rare at the same location with every pc.
    this error only occurs in about 1 in 75 installs. I have narrowed it down by
    my app when ran the first time sends me an email at 7 different check points,besides any errors. The app gets installed about 20 times a day
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  7. #7

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Error past end of file

    Quote Originally Posted by MartinLiss View Post
    I'm not exactly sure what your code looks like now but in the above code you don't need (and shouldn't have) the GoTo FirstLoad line and the FirstLoad label.
    thanks for adding that
    i have used line# and goto in many places without problems, but have seen
    where this this bad practise. Why ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Error past end of file

    That's the error you get when reading the file, correct? Do you get any errors while writing the file? If not checking, maybe you should.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Error past end of file

    Quote Originally Posted by LaVolpe View Post
    That's the error you get when reading the file, correct? Do you get any errors while writing the file? If not checking, maybe you should.
    yes that was the error when reading the file. I corrected that by adding the check for the file being empty eg:
    If FileExists(File1) And FileLen(File1) > 0 Then
    now i am trying to determine why the files is empty and correct it. the app creates the file, but does not write the value to the file and does not goto the error handler.
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  10. #10

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Error past end of file

    I also posted this question at experts exchange, the answer:
    You're re-using "fnumber" for two different files...

    I would either re-assign "fnumber" with FreeFile() before using it with the second file or change to fnumber2 instead.

    So at line #39 you could do:

    fnumber = FreeFile()

    Or complete switch to "fnumber2":

    fnumber2 = FreeFile()
    Open File2 For Output As #fnumber2
    Count2 = 1
    Print #fnumber2, Count2
    Close #fnumber2
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Error past end of file

    Quote Originally Posted by isnoend07 View Post
    I also posted this question at experts exchange, the answer:
    You're re-using "fnumber" for two different files...

    I would either re-assign "fnumber" with FreeFile() before using it with the second file or change to fnumber2 instead.

    So at line #39 you could do:

    fnumber = FreeFile()

    Or complete switch to "fnumber2":

    fnumber2 = FreeFile()
    Open File2 For Output As #fnumber2
    Count2 = 1
    Print #fnumber2, Count2
    Close #fnumber2
    Code:
    FirstLoad:
    505       fnumber = FreeFile()
    510       Open File1 For Output As #fnumber
    520        Count1 = 1
    530        Print #fnumber, Count1
    540       Close #fnumber
              
    545       fnumber = FreeFile()
    550       Open File2 For Output As #fnumber
    560        Count2 = 1
    570        Print #fnumber, Count2
    580       Close #fnumber
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: [RESOLVED] Error past end of file

    Thanks everyone
    I have created a new exe with reassigning freefIle. Now i will wait with my rabbits foot and four leaf clover
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  13. #13
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Error past end of file

    Quote Originally Posted by isnoend07 View Post
    thanks for adding that
    i have used line# and goto in many places without problems, but have seen
    where this this bad practise. Why ?
    Because it can lead to spaghetti code and I've rarely ever seen cases where it's actually needed except of course for On Error GoTo.

  14. #14
    New Member
    Join Date
    Apr 2016
    Posts
    1

    Re: Error past end of file

    isnoend07,
    I just joined VBForums and found this old post of yours. I'm having the same issue that looks like you might have been having and wasn't sure if you could be of any help. The app that I've created is distributed to an OEM's customers and is used to save & load operation parameters for the app The app may run for months without a customer having an issue and then it will pop up with an error 62 Input past end of file. Quite a while back after listening to a report of a user that experienced the problem I now output the same data to a second file that can be recalled if the error 62 comes up to input the data from the 2nd file and recreate the first file. The problem I now have is it looks like it is also happening to the 2nd file. Both files are opened at the same time in the same procedure. Like you, this has been a very difficult thing to pin down as I only hear about it once every 3-4 months.

    (Below is an example of my code, I'm using file numbers instead of FreeFile)

    Open x.dat for Output as 1
    Open x2.dat for Output as 2
    Write #1, data, data, data
    Write #2, data, data, data
    Write #1, data, data, data
    Write #2, data, data, data
    etc
    Close 1
    Close 2

    Thanks in advance for any ideas.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width