[RESOLVED] Reading from a file
I have an app that reads a text file and places the data into a listview.
It was working fine. Now I have added a column to the listview and there is more information in the saved file.
The file that I am loading into the listview will have a date followed by a tab and then a filepath. For example:
12/25/2001 C:\Myfolder\myfile.doc
That line needs to be placed in a listview, although the columns are reversed. Column 1 is the path and column 2 is the date.
Code:
Private Sub cmdLoad_Click()
Dim FileNum As Integer
Dim RecordCount As Long
Dim strFilePath, MyFile As String
Dim dteDate As Date
'Clear listbox
'List1.Clear
ListView1.ListItems.Clear
FileNum = FreeFile
RecordCount = 0
dlgLoadFile.DialogTitle = "Load a text file"
dlgLoadFile.Filter = "Text Files (*.txt)*.txt"
dlgLoadFile.ShowOpen
If Len(dlgLoadFile.FileName) <> 0 Then
MyFile = dlgLoadFile.FileName
Open dlgLoadFile.FileName For Input As #FileNum
Do Until EOF(FileNum)
Input #FileNum, strFilePath
'Get file type of first path
If RecordCount = 0 Then
GlobalFileType = "*." & Right(strFilePath, 3)
RecordCount = RecordCount + 1
Else
If strFilePath = "" Then
'Do nothing
Else
If Right(strFilePath, 3) <> Right(GlobalFileType, 3) Then
MsgBox "The file contains filenames with different extensions." & vbCrLf & _
"Make sure all filenames listed in the text file have the same extension.", _
vbCritical, "Error"
'List1.Clear
ListView1.ListItems.Clear
Exit Sub
Else
RecordCount = RecordCount + 1
End If
End If
End If
'List1.AddItem strFilePath
ListView1.ListItems.Add strFilePath
Loop
Close #FileNum
'Enable Check Links Button
cmdCheckLinks.Enabled = True
StatusBar1.Panels(3).Text = "File loaded."
Else
'Do nothing
End If
End Sub