Results 1 to 6 of 6

Thread: [RESOLVED] Input Past End Of File

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Resolved [RESOLVED] Input Past End Of File

    A directory has many sub-directories. Each of the sub-directories have a single text file. The name of the text file is exactly the same as the name of the directory in which it resides (of course, the text files have the .txt extension which the sub-directories don't). I want to read the contents of these text filea. The contents of the text files look like this (all the text files will not have the same contents):

    "Google","http://www.google.com"
    "Yahoo","http://www.yahoo.com"
    "Hotmail","http://www.hotmail.com"
    "MSN","http://www.msn.com"


    The Form has a DirListBox which lists all the sub-directories. This is how I am trying to read the text files:

    Code:
    For z = 0 To dir1.ListCount - 1
        'dir1 will have the entire path along with the directory name. I want only the
        'directory name; hence using some String functions to retrieve just the
        'directory name
    
        DirName = Right(dir1.List(z), Len(dir1.List(z)) - InStrRev(dir1.List(z), "\"))
        FileName = DirName & "\" & DirName & ".txt"
    
        If (Dir(FileName) <> vbNullString) Then
            Open FileName For Input As #iFile
            Data = Split(Input(LOF(1), 1), vbCrLf)
    
            'populating the contents of each text file in a TreeView
            'the sub-directory become the Parent nodes
            'the contents of the text files become the Child nodes
        End If
    Next
    Now what I find is on some occasions, VB generates the following error:

    Input past end of file.

    pointing to the red line in the above code. When I move the mouse over the variable FileName in the VB IDE, it points to the text file that resides in the 1st sub-directory.

    What's causing this error & how do I resolve it?

    Please note that NONE of the text files in the different sub-directories are empty. As already mentioned, this error gets generated only sometimes & not always; so I can't comprehend under what circumstances does this error get thrown.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  2. #2

  3. #3

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Input Past End Of File

    So what's the solution? How do I resolve it?


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  4. #4

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Input Past End Of File

    dim iFile as integer
    iFile=freefile
    ....
    Data = Split(Input(LOF(iFile), 1), vbCrLf)
    ....
    close iFile

  6. #6

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Input Past End Of File

    Yes....yes...right


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

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