|
-
Jan 20th, 2006, 01:11 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Open Routine Problems...
Hey, i've just encountered a very strange problem with my open routine in one of my programs.
All its meant to do is open the given FileName, simply by putting it into Text1
Here is my routine, can anyone see where i have gone wrong ?
VB Code:
Private Function Open_File(Filename As String)
On Error GoTo Hell
Dim lFileLength As Long
Dim iFileNum As Integer
'Get a free file number and open the file
iFileNum = FreeFile
Open Filename For Input As iFileNum
'Get the length of the file and
'read it into the text box
lFileLength = LOF(iFileNum)
Text1.Text = Input(lFileLength, iFileNum)
Close iFileNum
Hell:
End Function
-
Jan 20th, 2006, 01:16 PM
#2
Re: Open Routine Problems...
don't have vb right now but i use
intfile = freefile()
essentially creating an array of possible freefiles to use, i dont know if this is the problem, are there any errors?
-
Jan 20th, 2006, 01:16 PM
#3
Thread Starter
Frenzied Member
Re: Open Routine Problems...
Actually just done this...
VB Code:
Private Function Open_File(Filename As String)
On Error GoTo Hell
Dim lFileLength As Long
Dim iFileNum As Integer
'Get a free file number and open the file
iFileNum = FreeFile
Open Filename For Input As iFileNum
'Get the length of the file and
'read it into the text box
lFileLength = LOF(iFileNum)
Text1.Text = Input(lFileLength, iFileNum)
Close iFileNum
Hell:
MsgBox Err.Number & " : " & Err.Description
End Function
And i get Error 62: Input past end of file
Any help ?
-
Jan 20th, 2006, 01:17 PM
#4
Re: Open Routine Problems...
-
Jan 20th, 2006, 01:20 PM
#5
Thread Starter
Frenzied Member
Re: Open Routine Problems...
 Originally Posted by techgnome
try iFileLength - 1
-tg
Still gives the same eror, oh... and this uses the Command$ passed form Sub Main() in a module... Thats where it usually gets its filename from, but i also have it passed from a comman dialog too.
With the Command$ i get "Error 52: Bad file Name or Number"
So, is there a way to strip out the filename passed by Command$ ? Like maybe it has blank space or something ?
-
Jan 20th, 2006, 01:23 PM
#6
Re: Open Routine Problems...
Check the value of Command$ before passing it... see if it's really what you expect... as far as spaces go, it shouldn't matter. I've opened files before where there were spaces in the folder names, so I doubt that has any affect.
I'm still caught up on why you are getting the Input past end of time error...
-tg
-
Jan 20th, 2006, 01:25 PM
#7
Thread Starter
Frenzied Member
Re: Open Routine Problems...
 Originally Posted by techgnome
Check the value of Command$ before passing it... see if it's really what you expect... as far as spaces go, it shouldn't matter. I've opened files before where there were spaces in the folder names, so I doubt that has any affect.
I'm still caught up on why you are getting the Input past end of time error...
-tg
Checked Command$ and the Filename thats being passed, they are both exactly what i expect them to be, so, in theory they should work. But still, i get Bad File Name Or Number (Error 52).
So, that is a little strange.
I still get error 62 as well.
Not liking this one bit.
-
Jan 20th, 2006, 01:37 PM
#8
Re: Open Routine Problems...
Don't know what to tell you... I don't use command parameters so I've never had issues with it.... it is strange though....
-tg
-
Jan 20th, 2006, 01:41 PM
#9
Thread Starter
Frenzied Member
Re: Open Routine Problems...
Ok, i have modified how i make my command$ string be sent into my routine.
It now works like that, but, i know whats causing the Input past end of file error occur.
Just un-handled characters in files, i really didn't think of this.
So far it works perfectly on text files like its meant too 
I'll update this post if anything else goes wrong.
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
|