by Sathiyan (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 15th October 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Convert file to List view
API Declarations
Dim Data As String
Dim Dataop As String
Dim currpos As String
Dim prevpos As String
Dim listing(10) As String
Dim itm As ListItem
'Controls needed 1.ListView(name lv)
'File in C:\.
lv.View = lvwReport
lv.ColumnHeaders.Add , , "User ID"
lv.ColumnHeaders.Add , , "Key Name"
lv.ColumnHeaders.Add , , "Description"
'List View Column Headers
FilePath = "C:\test.txt"
'Asks the user for some input via an input box.
Open FilePath For Input As #1
'Opens the file given by the user.
Do Until EOF(1)
'Does this loop until End Of File(EOF) for file number 1.
Line Input #1, Data
'Read one line and puts it into the varible Data.
If Data <> "" Then
currpos = 1
prevpos = 1
i = 1
While Len(Data) <> currpos
currpos = InStr(prevpos, Data, ",")
If currpos = 0 Then
currpos = Len(Data)
Dataop = Mid(Data, prevpos, currpos)
listing(i) = Dataop
Else
Dataop = Mid(Data, prevpos, currpos - prevpos)
listing(i) = Dataop
prevpos = currpos + 1
End If
i = i + 1
Wend
Set itm = lv.ListItems.Add(, , listing(1))
itm.SubItems(1) = listing(2)
itm.SubItems(2) = listing(3)
End If
Loop
Close #1
'Closes this file.
End Sub