|
-
Jan 18th, 2008, 11:24 AM
#1
Thread Starter
Frenzied Member
[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?
-
Jan 18th, 2008, 11:47 AM
#2
Re: Input Past End Of File
iFile isn't always = 1 even though your Split line assumes it is.
-
Jan 18th, 2008, 02:19 PM
#3
Thread Starter
Frenzied Member
-
Jan 18th, 2008, 02:27 PM
#4
Re: Input Past End Of File
Well I can't see if/where you are setting iFile but
Data = Split(Input(LOF(iFile), 1), vbCrLf)
Last edited by MartinLiss; Jan 18th, 2008 at 02:48 PM.
-
Jan 18th, 2008, 02:43 PM
#5
Re: Input Past End Of File
dim iFile as integer
iFile=freefile
....
Data = Split(Input(LOF(iFile), 1), vbCrLf)
....
close iFile
-
Jan 18th, 2008, 02:56 PM
#6
Thread Starter
Frenzied Member
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
|