[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?
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.
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.
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:
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
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
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.