Results 1 to 6 of 6

Thread: Read or Not from TXT file

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Skudeneshavn, Norway
    Posts
    38
    Hi

    This code reads a txt file line by line
    and adds it to a listbox, and it works,
    but there is another thing I want i to
    do. That is to NOT read empty lines.

    Sometimes there are empty lines at the end
    of txt files. Its easy to check by pressing
    down arrow until thr cursor stops.
    Is there some code to check for this and NOT
    read it.

    'My code

    Private Sub mnuOpen_Click()

    List1.Clear
    Dim InputData

    On Error GoTo mnuÅpneErr
    CommonDialog1.Filter = "ASCII-tekst (*.txt)|*.txt"
    CommonDialog1.DefaultExt = "txt"
    CommonDialog1.Flags = cdlOFNHideReadOnly
    CommonDialog1.ShowOpen
    Open CommonDialog1.FileName For Input As #1
    Do While Not EOF(1)
    Line Input #1, InputData

    InputData = Replace(InputData, "\", " - ")
    InputData = Replace(InputData, "/", " - ")
    InputData = Replace(InputData, ":", ".")
    InputData = Replace(InputData, "*", "'")
    InputData = Replace(InputData, "?", "")
    InputData = Replace(InputData, Chr(34), "'")
    InputData = Replace(InputData, "<", "'")
    InputData = Replace(InputData, ">", "'")
    InputData = Replace(InputData, "|", "")

    If InputData = "" Then
    KeyPress = Delete
    End If

    InputData = Trim$(InputData)
    List1.AddItem InputData + ".mp3"

    Loop
    Close #1
    Command1.Enabled = True

    mnuÅpneErr:
    Exit Sub
    End Sub



    Well, I hope you can help

    Best Regards,

    Chris Davidsen
    Christian Davidsen

    If you go to sleep with an itchy
    ass, you wake up with smelly fingers.

  2. #2

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Skudeneshavn, Norway
    Posts
    38

    I forgot somethig

    the txt files contains a songtitle list

    ex.

    01. The wonder of you
    02. Roustabout

    and in the list box it will be

    01. The wonder of you.mp3
    02. Roustabout.mp3

    and say if there are two emptylines in the txt file
    it will be like this

    01. The wonder of you.mp3
    02. Roustabout.mp3
    .mp3
    .mp3

    That's all.

    Christian Davidsen

    If you go to sleep with an itchy
    ass, you wake up with smelly fingers.

  3. #3
    Guest
    Just after this line:
    Code:
    Line Input #1, InputData
    Put this:
    Code:
    InputData = Trim(InputData)
    InputData = Replace(InputData, Chr(0), "")
    If InputData = "" Then
        'The line is blank
    End If

  4. #4
    Guest
    Or, an easier way.
    replace this:
    Code:
    InputData = Trim$(InputData)
    List1.AddItem InputData + ".mp3"
    With this:
    Code:
    InputData = Trim(InputData)
    If Len(InputData) <> 0 Then
        List1.AddItem InputData & ".mp3"
    End If
    I think this is easier.

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Skudeneshavn, Norway
    Posts
    38

    hmmm

    The line is black with your code
    but it is still read as an empty
    line.

    If the cursor can blink on a "empty line"
    its not really empty.

    so there must be another code

    But thanks anyway

    Chris
    Christian Davidsen

    If you go to sleep with an itchy
    ass, you wake up with smelly fingers.

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Skudeneshavn, Norway
    Posts
    38

    No further help needed !

    the code I needed was

    If InputData = "" Then
    InputData.DeleteLines
    End If

    But thank you very much for trying Sc0rp

    Chris Davidsen
    Christian Davidsen

    If you go to sleep with an itchy
    ass, you wake up with smelly fingers.

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