|
-
Jan 25th, 2010, 04:18 PM
#1
Thread Starter
Member
[RESOLVED] Help with opening a text file
Here is my code:
Code:
Private Sub Form_Load()
Dim Channel As Integer
Channel = FreeFile(0)
Open App.Path & "\HELPTEXT.txt" For Input As #Channel
Text1.Text = Input$(LOF(Channel), 1)
Close #Channel
End Sub
When I open the form it comes up with an error saying "Bad file mode". As far as I'm aware, you open for Input if you want to do what I'm doing. Are there any other factors that might be affecting this, or have I just got the wrong mode?
Thanks
-
Jan 25th, 2010, 04:42 PM
#2
Re: Help with opening a text file
I created a new project with 1 textbox and copy-pasted your code as shown into my form. Created the HelpText.txt file at the required location and all worked perfectly.
Is the code you posted the exact code you are using ?
Can you step through your code line by line and post which line it fails on ?
Can you also check in debug mode/immediate window what the expected location is of App.Path & "\HELPTEXT.txt" and check the file exists there.
Kind Regards,
Optional
If you feel this post has helped in answering your question please return the favour and Rate this post.
If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.
VB6 - (DataGrid) Get the Row selected with the right mouse button
-
Jan 25th, 2010, 04:50 PM
#3
Thread Starter
Member
Re: Help with opening a text file
Right. This code is all that's in the form. It fails on the line "Text1.Text = Input$(LOF(Channel), 1)" and the error message comes up "Bad File Mode". The file also exists and it's in the right place.
I also have to say that this was working earlier :$ Although this is the only code in the form, it's only one of the forms in my project. I have been tinkering with the rest of the project for a while, so I have no idea when this stopped working. The thing is, I didn't think that changing other parts of the program would lead to "Bad file mode" error - it's either the correct mode or it's not. What I've said probably hasnt been much help, sorry. It's so frustrating since it was working a-ok earlier :$.
Edit: I've tried printing the file with Line Input into a PictureBox, and it works. I think I might just use this method instead, although the previous *did* work and still should but just doesn't for some reason .
Last edited by MisterM2402; Jan 25th, 2010 at 04:59 PM.
-
Jan 25th, 2010, 05:00 PM
#4
Re: Help with opening a text file
Have you created a function or form or something else and named it INPUT? If so, that may be the problem.
-
Jan 25th, 2010, 05:01 PM
#5
Thread Starter
Member
Re: Help with opening a text file
 Originally Posted by LaVolpe
Have you created a function or form or something else and named it INPUT? If so, that may be the problem.
Nope. Nothing else in the code for that form. Thanks anyway. I'll just mark this resolved.
-
Jan 25th, 2010, 05:12 PM
#6
Re: Help with opening a text file
Does it make a difference if you use the #channel in the input$ command instead of the 1 ?
Code:
Private Sub Form_Load()
Dim Channel As Integer
Channel = FreeFile(0)
Open App.Path & "\HELPTEXT.txt" For Input As #Channel
Text1.Text = Input$(LOF(Channel), #Channel)
Close #Channel
End Sub
Because you said that it used to work and now it doesn't. Did you add code anywhere, even on another form or module, which uses that same file but opens it for binary or append,etc... ?
Kind Regards,
Optional
If you feel this post has helped in answering your question please return the favour and Rate this post.
If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.
VB6 - (DataGrid) Get the Row selected with the right mouse button
-
Jan 26th, 2010, 11:48 AM
#7
Thread Starter
Member
Re: Help with opening a text file
 Originally Posted by Optional
Does it make a difference if you use the #channel in the input$ command instead of the 1 ?
Code:
Private Sub Form_Load()
Dim Channel As Integer
Channel = FreeFile(0)
Open App.Path & "\HELPTEXT.txt" For Input As #Channel
Text1.Text = Input$(LOF(Channel), #Channel)
Close #Channel
End Sub
Because you said that it used to work and now it doesn't. Did you add code anywhere, even on another form or module, which uses that same file but opens it for binary or append,etc... ?
"Channel" doesnt seem to make a difference (tried it using 3 instead, but nothing changed). Nope, this form is the only place where that file is needed. It's just so confusing :S
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
|