CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2008
    Posts
    34

    [RESOLVED] .: "Input past end of file" err. keep occuring. Please help.

    Somebody please help me on how to solve:

    Code:
    Err.Number = 62
    Err.Description = "Input past end of file"
    The code look like below:

    Code:
    Option Explicit
    
    Dim mGenBlank, mGen1, mGen2 As String
    Dim mSupport(24) As String
    Dim FileLoc As String		'The Location of the File
    
    '============================== LOAD EVENT ===================================='
    Private Sub cmdUpdate_Click()
    'On Error GoTo The_Error_Handler
    FileLoc = "C:\MyData.dat"
    
    Open FileLoc For Input As #1
         Line Input #1, mGenBlank
         Line Input #1, mGen1
         Line Input #1, mGen2
              
         txtManu.Text = Mid$(mGen1, 14, Len(mGen1))
         txtModel.Text = Mid$(mGen2, 7, Len(mGen2))
    Close #1
    
    Open FileLoc For Input As #2
         Line Input #2, mSupport(0)
         Line Input #2, mSupport(1)
         Line Input #2, mSupport(2)
         Line Input #2, mSupport(3)
         
         Line Input #2, mSupport(4)
         Line Input #2, mSupport(5)
         Line Input #2, mSupport(6)
         Line Input #2, mSupport(7)   'The Error goes by this line.
    	                                   'mSupport(7) is the String that contains empty line
    	                                   'in the file ("C:\MyData.dat")
         
         txtSupport.Text = Mid$(mSupport(4), 8, Len(mSupport(4)) - 8) & vbCrLf & _
                           Mid$(mSupport(5), 8, Len(mSupport(5)) - 8) & vbCrLf & _
                           Mid$(mSupport(6), 8, Len(mSupport(6)) - 8) & vbCrLf & _
                           Mid$(mSupport(7), 8, Len(mSupport(7)) - 8)
    Close #2
    Exit Sub
    
    'The_Error_Handler:
    End Sub

    The core of problem is that, I want to add a blank line (no text) from the file
    ("C:\MyData.dat") into a Textbox of the form.
    But whenever I run it, the Error like stated above keeps showing up. I cannot
    solve it. So, what should I do?

    Thanks in advance.
    yoms
    yoms

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: .: "Input past end of file" err. keep occuring. Please help.

    Most likely there is no more line to read for this statement:
    Line Input #2, mSupport(7)
    You can overcome that by a conditional
    Code:
      If Not EoF(2) Then Line Input #2, mSupport(7)
    If there is no more data mSupport(7) stays empty without producing an error.
    If in doubt post a sample data file for us to see what's really in there.

  3. #3
    Join Date
    Mar 2008
    Posts
    34

    Re: .: "Input past end of file" err. keep occuring. Please help.

    Ya, I should have posted the attachment, but unfortunately I'm not at home right now so I'm not able to post it now.
    But i'll check soon right after I reach home.

    Thanks for you assistance.
    yoms

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: .: "Input past end of file" err. keep occuring. Please help.

    Watch out. If you use the conditional like I showed, you will get another error:
    Code:
    txtSupport.Text = Mid$(mSupport(4), 8, Len(mSupport(4)) - 8) & vbCrLf & _
                           Mid$(mSupport(5), 8, Len(mSupport(5)) - 8) & vbCrLf & _
                           Mid$(mSupport(6), 8, Len(mSupport(6)) - 8) & vbCrLf & _
                           Mid$(mSupport(7), 8, Len(mSupport(7)) - 8)
    You can not take Mid$() from empty strings.
    But if you are sure this line is always empty, you simply apend mSupport(7) as is.
    Otherwise you'd have to use another conditional.

  5. #5
    Join Date
    Mar 2008
    Posts
    34

    Arrow Re: .: "Input past end of file" err. keep occuring. Please help.

    Thanks for the ideas. Here, I guess by looking at the attachment, I'm sure you'll know what I'm up to
    Ok, please click on the Update button to see how it looks.

    I got no problem at General Section.

    But the matter starts right after the 17th, 18th line and so on.
    They don't load anymore. What I really wish is, that they (next lines) will have no limit (keep loading) of being loaded into the txtSupport.Text box.
    (That's why I enabled 3 - Both scrollbar; in ScrollBars property)

    I've used :
    Code:
    ReDim mSupport(0 to 19) As String
    But actually, I want to have an unlimited array. Is that possible?

    Oops, nearly forget. Please have a look at the code below:

    Code:
    txtSupport.Text = Mid$(mSupport(5), 8, Len(mSupport(5)) - Len(Right$(mSupport(5), 8))) & vbCrLf & _
                          Mid$(mSupport(6), 8, Len(mSupport(6)) - Len(Right$(mSupport(6), 8))) & vbCrLf & _
                          Mid$(mSupport(7), 8, Len(mSupport(7)) - Len(Right$(mSupport(7), 8))) & vbCrLf & _
                          Mid$(mSupport(8), 8, Len(mSupport(8)) - Len(Right$(mSupport(8), 8))) & vbCrLf & _
                          Mid$(mSupport(9), 8, Len(mSupport(9)) - Len(Right$(mSupport(9), 8))) & vbCrLf & _
                          Mid$(mSupport(10), 8, Len(mSupport(10)) - Len(Right$(mSupport(10), 8))) & vbCrLf & _
                          Mid$(mSupport(11), 8, Len(mSupport(11)) - Len(Right$(mSupport(11), 8))) & vbCrLf & _
                          Mid$(mSupport(12), 8, Len(mSupport(12)) - Len(Right$(mSupport(12), 8))) & vbCrLf & _
                          Mid$(mSupport(13), 9, Len(mSupport(13)) - Len(Right$(mSupport(13), 9))) & vbCrLf & _
                          Mid$(mSupport(14), 9, Len(mSupport(14)) - Len(Right$(mSupport(14), 9))) & vbCrLf & _
                          Mid$(mSupport(15), 9, Len(mSupport(15)) - Len(Right$(mSupport(15), 9))) & vbCrLf & _
                          Mid$(mSupport(16), 9, Len(mSupport(16)) - Len(Right$(mSupport(16), 9))) & vbCrLf & _
                          Mid$(mSupport(17), 9, Len(mSupport(17)) - Len(Right$(mSupport(17), 9))) & vbCrLf & _
                          Mid$(mSupport(18), 9, Len(mSupport(18)) - Len(Right$(mSupport(18), 9))) & vbCrLf & _
                          Mid$(mSupport(19), 9, Len(mSupport(19)) - Len(Right$(mSupport(19), 9)))
    I guess it's too messy or even quite confusing.. Is there a way to make it simpler?

    Thank you so much.
    Attached Files Attached Files
    Last edited by yom; March 29th, 2008 at 03:34 AM.
    yoms

  6. #6
    Join Date
    Dec 2006
    Location
    Pune, India.
    Posts
    579

    Re: .: "Input past end of file" err. keep occuring. Please help.

    Use this:

    Code:
    Private Sub cmdUpdate_Click()
        Dim strLine As String
        Dim EqualsPos As Integer
        
        FileLoc = App.Path & "\Data\oeminfo.ini"
        
        Open FileLoc For Input As #2
             Line Input #2, mGenBlank
             Line Input #2, mGen1
             Line Input #2, mGen2
                 
             txtManu.Text = Mid$(mGen1, 14, Len(mGen1))
             txtModel.Text = Mid$(mGen2, 7, Len(mGen2))
       
         
            While Not EOF(2)
                Line Input #2, strLine
                
                'Find the '=' in line
                EqualsPos = InStr(1, strLine, "=")
                
                If EqualsPos <> 0 Then
                    txtSupport.Text = txtSupport.Text & Replace(Mid(strLine, EqualsPos + 1, Len(strLine)), Chr(34), "") & vbNewLine
                End If
                
            Wend
            
        Close #2
          
    End Sub

  7. #7
    Join Date
    Mar 2008
    Posts
    34

    Re: .: "Input past end of file" err. keep occuring. Please help.

    thanks for the ideas.
    yoms

  8. #8
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: .: "Input past end of file" err. keep occuring. Please help.

    Well, yes. Study Shaiks sample carefully.
    It shows how to go for an unpredictable amount of lines.
    If you actually need to store the same lines in an array too, you can use the ReDim on the array like that within the loop.

    Code:
       dim LineCount as Integer 'need that for the counting of the lines
       dim tmp as string 'need a temporary string
    
    ... 'code goes like Shaikh suggested
    
            While Not EOF(2)
                Line Input #2, strLine
                
                'Find the '=' in line
                EqualsPos = InStr(1, strLine, "=")
                
                If EqualsPos <> 0 Then
                    tmp = txtSupport.Text & Replace(Mid(strLine, EqualsPos + 1, Len(strLine)), Chr(34), "") & vbNewLine
                    txtSupport.Text = tmp
                    LineCount = LineCount + 1
                    Redim Preserve mSupport(LineCount)
                    mSupport(LineCount) = tmp
                End If
                
            Wend

  9. #9
    Join Date
    Mar 2008
    Posts
    34

    Re: .: "Input past end of file" err. keep occuring. Please help.

    Ya, that's true. It shows an unpredictable amount of lines. So that's how to do
    Thanks a lot
    yoms

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

Featured