Results 1 to 12 of 12

Thread: problem with eof...

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    32

    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...

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

    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
    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}

  3. #3
    Hyperactive Member Quiver318's Avatar
    Join Date
    Sep 2007
    Posts
    260

    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.

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

    Re: problem with eof...

    Quote Originally Posted by Quiver318 View Post
    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.
    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
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    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!

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

    Re: problem with eof...

    Quote Originally Posted by Dungeon Keeper View Post
    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.
    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}

  7. #7
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: problem with eof...

    I think that a look at the data in that slang.txt file would resolve this problem, if it isn't resolved already

    Edit: Thanks for that link LaVolpe
    No, that wont do!

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    32

    Re: problem with eof...

    well thanks but the real problem was that i acidently put a , where it shouldn't have been xD

  9. #9
    Hyperactive Member Quiver318's Avatar
    Join Date
    Sep 2007
    Posts
    260

    Re: problem with eof...

    Quote Originally Posted by LaVolpe View Post
    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.

  10. #10
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    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.

  11. #11
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    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.

  12. #12
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: problem with eof...

    Quote Originally Posted by DigiRev View Post
    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
  •  



Click Here to Expand Forum to Full Width