How to open files to a listbox using VB6. Opening a Text File to a Listbox to a listbox. Make sure you have a CommonDialog (comdlg32.ocx) control added to your form. Put something like this in a button:
On Error GoTo handleError
Dim fileName As String, listItem As String
CommonDialog1.CancelError = True
CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
CommonDialog1.FilterIndex = 0
CommonDialog1.ShowOpen
fileName = CommonDialog1.fileName
List1.Clear
Open fileName For Input As #1
Do While Not EOF(1)
Line Input #1, listItem
If Not (listItem = "") Then
List1.AddItem listItem
End If
Loop
Close #1
handleError: Exit Sub
0 comments:
Posting Komentar