|
-
Jun 19th, 2009, 02:40 PM
#1
Thread Starter
Member
problem with eof...
so im running this bit of code...
Private Sub Command1_Click()
Dim theinput As String
Dim notfound As Boolean
theinput = UCase(Text1.Text)
Open "C:\Users\Asus Man\programing stuff\slang\slang.txt" For Input As #1
Do While Not EOF(1)
Input #1, slang, means
If theinput = slang Then
Picture1.Cls
Picture1.Print means
notfound = True
End If
Loop
Close #1
If notfound = False Then
Picture1.Cls
Picture1.Print "the slang could not be found"
End If
End Sub
but i keep getting the error: input past end of file
i dont really get it...
-
Jun 19th, 2009, 03:39 PM
#2
Re: problem with eof...
I haven't used "Input " that way in years. If I remember correctly, you are getting two values from the file: slang & means. I don't see where those are declared but am assuming they are strings. If I do recall correctly, then if your file doesn't contain pairs of values throughout the file, you will get the error. This is because your code is trying to input slang, which works, but there is no more data to input means -- error. I would imagine your error is probably caused by a blank line within your file. Worth a check. If you can't figure it out, you might want to post your file
-
Jun 19th, 2009, 03:56 PM
#3
Hyperactive Member
Re: problem with eof...
The Input command will read a line until it reaches CRLF (noting the end of the line), and it will then move on to the next line. If the last line in your file does not have CRLF, the routine will read past the end of file and will throw an error.
To fix this, open your list file in a common editor like Notepad. Go to the very last character of the very last line, and then press the Enter key! This will create a a CRLF at the end of that line and your cursor will jump to the next line below it. Save your file, and then run your routine. It should work now.
-
Jun 19th, 2009, 05:59 PM
#4
Re: problem with eof...
 Originally Posted by Quiver318
The Input command will read a line until it reaches CRLF (noting the end of the line), and it will then move on to the next line. If the last line in your file does not have CRLF, the routine will read past the end of file and will throw an error.
Not quite. Line Input #n will read an entire line. The code posted in #1 above is not using Line Input.
Edited: It really depends on the formatting of the text/data within the file.
Example: Apples, Bananas, Grapes :: Input #n, strFruit will read each word individually even if they are on the same line
Example: Apples Bananas Grapes :: Input #n, strFruit will read entire line in this case; same result as using Line Input
Last edited by LaVolpe; Jun 19th, 2009 at 06:12 PM.
-
Jun 19th, 2009, 06:13 PM
#5
Fanatic Member
Re: problem with eof...
So input reads a whole line, or until it reaches a comma character?
Edit: Obviously there is a lack of commas in that slang.txt
Last edited by Dungeon Keeper; Jun 19th, 2009 at 06:21 PM.
No, that wont do!
-
Jun 19th, 2009, 06:24 PM
#6
Re: problem with eof...
 Originally Posted by Dungeon Keeper
So input reads a whole line, or until it reaches a comma character?
Edit: Obviously there is a lack of commas in that slang.txt 
MSDN
Code:
... When read, standard string or numeric data is assigned to variables without modification.
The following table illustrates how other input data is treated:
Data Value assigned to variable
Delimiting comma or blank line Empty
#NULL# Null
#TRUE# or #FALSE# True or False
#yyyy-mm-dd hh:mm:ss# The date and/or time represented by the expression
#ERROR errornumber# errornumber (variable is a Variant tagged as an error)
Double quotation marks (" ") within input data are ignored.
Note : You should not write strings that contain embedded quotation marks, for example, "1,2""X" for use with the Input # statement:
Input # parses this string as two complete and separate strings.
Data items in a file must appear in the same order as the variables in varlist and match variables of the same data type.
If a variable is numeric and the data is not numeric, a value of zero is assigned to the variable.
If you reach the end of the file while you are inputting a data item, the input is terminated and an error occurs.
Note : To be able to correctly read data from a file into variables using Input #, use the Write # statement instead of the
Print # statement to write the data to the files. Using Write # ensures each separate data field is properly delimited.
Last edited by LaVolpe; Jun 19th, 2009 at 06:33 PM.
-
Jun 19th, 2009, 06:34 PM
#7
-
Jun 19th, 2009, 07:18 PM
#8
Thread Starter
Member
Re: problem with eof...
well thanks but the real problem was that i acidently put a , where it shouldn't have been xD
-
Jun 19th, 2009, 08:57 PM
#9
Hyperactive Member
Re: problem with eof...
 Originally Posted by LaVolpe
Not quite. Line Input #n will read an entire line. The code posted in #1 above is not using Line Input.
You are quite right. I had confused Input with LineInput. Sometimes all these commands run around in my head until I cannot sleep at night. Sorry for the confusion.
-
Jun 19th, 2009, 11:11 PM
#10
Re: problem with eof...
to prevent commas from screwing your logic up, place all your data in quotes when you save it to the file.
print #1, chr(34) + data + chr(34)
the quotes won't show up when you read the data. Note that this only works with string data.
-
Jun 19th, 2009, 11:42 PM
#11
Re: problem with eof...
I think the Write statement prints with quotes, but I could be wrong.
I mainly only do binary reading, and if not, it's usually Line Input or reading the entire file at once.
-
Jun 20th, 2009, 09:12 AM
#12
Re: problem with eof...
 Originally Posted by DigiRev
I think the Write statement prints with quotes, but I could be wrong.
I mainly only do binary reading, and if not, it's usually Line Input or reading the entire file at once.
possibly. I've never used it. I had this issue with a custom database that had to fit on a floppy disk. I put it in csv format and it was causing issue with the description of some of the vehicles in it. I had originally just stripped out all the commas but as i was transferring jobs i had to future-proof it against new users who might add a new one. If i'm not mistaken (and i may be) there's another format where the columns are separated by tabs and it doesn't have this issue at all.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|