Results 1 to 4 of 4

Thread: how open blank or empty text file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    183

    how open blank or empty text file

    hello
    how open blank or empty text file i used the code but not open file
    error show

    run time error 62
    input past end of file

    code

    Code:
    Private Sub Command1_Click()
    openFilename = "F:\pbsr100.txt"
    If Dir(openFilename) <> "" Then
    Dim I As String
    Open openFilename For Input As #1
    Do
    Input #1, I
    List1.AddItem I
    Loop Until EOF(1)
    Close #1
    Else
    End If
    End Sub
    Last edited by RobDog888; Feb 17th, 2019 at 12:28 PM. Reason: Added [Code] tags

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

    Re: how open blank or empty text file

    If it's blank then there is nothing to Input. You can test the size of the file to see if it's zero bytes
    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}

  3. #3
    Lively Member
    Join Date
    May 2017
    Posts
    81

    Re: how open blank or empty text file

    Two possibilities:
    1) Change the loop to test EOF before Input:
    Code:
        Do While Not EOF(1)
             Input #1, I
             List1.AddItem I
        Loop
    2) Add an error handler to catch the error.

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: how open blank or empty text file

    You can also reverse the position of the until making it
    Code:
    Do Until EOF(1)
    '
    '
    Loop

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