Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input Past end of file error when not

Status
Not open for further replies.

DaProgrammer

Programmer
May 27, 2004
22
US
Dear all:
For a weather program i am making, I have to input data from clientraw.txt (if you want to see the file goto into sequential variables a to z, then aa to zz, then aaa to zzz, and so on. Here is my code that when I put anymore variables than this it gives me an Input Past End Of File Error:
Code:
Open "A:\clientraw.txt" For Input As #1
Do While Not EOF(1)
Dim hh
    Input #1, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, hh, ii, z, aa, bb, cc, dd, ee, ff, gg
Loop
Close #1

I simply do not understand where my problem is. Is there an alternative method to inputing this data, each into seperate variables?

-Thanks Much in Advance,
Eric A. Hill

***NOTE, PLEASE IGNORE THE WORD WRAP!***
 
Your file appears to have 114 terms in it. Your Input # statement picks up 33 variables, so you will run the Input# line 3 times, then get an Input past End error half way through the 4th run through.

Use Line Input, then use Split function to separate the variables.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
could you give a scaled down example, im not familiar with the split function.

-Eric
 
Private Sub Command1_Click()
Dim InputData As String
Dim aryInput() As String
Dim i As Long

Open "A:\clientraw.txt" For Input As #1
Do Until EOF(1)
Line Input #1, InputData
aryInput = Split(InputData, " ")
For i = LBound(aryInput) To UBound(aryInput)
' Displays all array entries
MsgBox aryInput(i)
Next
Loop
Close #1

End Sub

Swi
 
This splits a string into separate elements, using a space as the element delimiter:
[tt]
Dim strInput as String
Dim strPrint() As String
Dim lngCount As Long
strInput = "abc def 123 456"
strPrint = Split(strInput, " ")
For lngCount = LBound(strPrint) To UBound(strPrint)
'your individual items are here in the array
Debug.Print strPrint(lngCount)
Next lngCount
[/tt]

Also check out the VB6 Helpfile on Split Function

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Whenever I try to do this, I get a "Sub or Function Not Defined' error and it highlights 'Split'.

-Eric
 
Are you using VB6 with up-to-date service packs?

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Negative, using VB 4.0 with updated service packs. I am trying this forum b/c there was no reply in the vb 4 forum. Also, alot of the VB5 and 4 are very closely related.

-Eric
 
The Split function does not exist prior to VB6.

Swi
 
In that case you may need to roll your own Split. It shouldn't be that hard. Take a string and a char for arguements. Walk the string one char at a time pushing the chars onto a temp string. When the char matches the char that was passed in push the temp string onto an array. When you get to the end return the array.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Or you could always use the function that Swi provided the link for (I clearly need to learn how to type faster) :)

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Swi-

I went to that link and all works except the first part...
Code:
Function Split(ByVal Text As String, Optional ByVal Delimiter As String = " ",Optional ByVal Limit As Long = -1, Optional CompareMethod As VbCompareMethod = vbBinaryCompare) As Variant

It highlights the the = " " after String and says 'Expected: list separator or )'

Almost there I think.... Thanks guys for all the help!

-Eric
 
How are you calling the function? Try this and see if you still get the error:

Private Sub Command1_Click()
Dim InputData As String
Dim aryInput() As String
Dim i As Long

Open "A:\clientraw.txt" For Input As #1
Do Until EOF(1)
Line Input #1, InputData
aryInput = Split(InputData, " ")
For i = LBound(aryInput) To UBound(aryInput)
' Displays all array entries
MsgBox aryInput(i)
Next
Loop
Close #1

End Sub


Function Split(ByVal Text As String, Optional ByVal Delimiter As String = " ", _
Optional ByVal Limit As Long = -1, Optional CompareMethod As _
VbCompareMethod = vbBinaryCompare) As Variant
ReDim res(0 To 100) As String
Dim resCount As Long
Dim length As Long
Dim startIndex As Long
Dim endIndex As Long

length = Len(Text)
startIndex = 1

Do While startIndex <= length And resCount <> Limit
' get the next delimiter
endIndex = InStr(startIndex, Text, Delimiter, CompareMethod)
If endIndex = 0 Then endIndex = length + 1

' make room in the array, if necessary
If resCount > UBound(res) Then
ReDim Preserve res(0 To resCount + 99) As String
End If
' store the new element
res(resCount) = Mid$(Text, startIndex, endIndex - startIndex)
resCount = resCount + 1

startIndex = endIndex + Len(Delimiter)
Loop

' trim unused values
ReDim Preserve res(0 To resCount - 1) As String

' return the array inside a Variant
Split = res()

End Function


Swi
 
It just highlights the = sign after String and says 'Expected: list separator or )'

-Eric
 
Does VB4 support optional parameters? I seem to recall that it doesn't. If that is the case then take out the Optional bits and the defauilt values.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
By doing what johnwm said to do, I now get...
Code:
Open "A:\clientraw.txt" For Input As #1
Do Until EOF(1)
Line Input #1, InputData
aryInput = Split(InputData, " ")
For i = LBound(aryInput) To UBound(aryInput)
    ' Displays all array entries
    MsgBox aryInput(i)
Next
Loop
Close #1

It highlights Split and says 'wrong number of arguements or invalid property assignments'

-Eric
 
Good point johnwm. I have only used VB5 before and that was a good bit ago but I can not recall if they are allowed.

Swi
 
This:
Function Split(ByVal Text As String, Optional ByVal Delimiter As String = " ", _
Optional ByVal Limit As Long = -1, Optional CompareMethod As _
VbCompareMethod = vbBinaryCompare) As Variant

should now read:
Function Split(ByVal Text As String, Delimiter As String) As Variant

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
....VB has too many error codes.....

new error!

Code:
Open "A:\clientraw.txt" For Input As #1
Do Until EOF(1)
Line Input #1, InputData
aryInput = Split(InputData, " ")
For i = LBound(aryInput) To UBound(aryInput)
    ' Displays all array entries
    MsgBox aryInput(i)
Next
Loop
Close #1

aryInput is highlighted and VB says:
'can't assign to a non-byte array'

-Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top