Results 1 to 7 of 7

Thread: [RESOLVED] Help with opening a text file

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    40

    Resolved [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

  2. #2
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    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



  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    40

    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.

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

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

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    40

    Re: Help with opening a text file

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

  6. #6
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    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



  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    40

    Re: Help with opening a text file

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



Click Here to Expand Forum to Full Width