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