Hi all,
I'm make a program to read text file.
I can read the text file but don't know how to write it to listview.
This my code to read into arrays:
Function ReadFileText(ByVal filename As String) As String
Dim handle As Integer
' ensure that the file exists
If Len(Dir$(filename)) = 0 Then
Err.Raise 53 ' File not found
End If
' open in binary mode
handle = FreeFile
Open filename$ For Binary As #handle
' read the string and close the file
ReadFileText = Space$(LOF(handle))
Get #handle, , ReadFileText
Close #handle
End Function
Private Sub Command1_Click()
Dim temp() As String
Dim temp2() As String
Dim FNArr() As String
Dim LNArr() As String
Dim AgeArr() As String
Dim BloddArr() As String
' split text file by new line (enter)
temp = Split(ReadFileText("D:\Mid Task\Data.txt"), vbNewLine)
' get how many rows in array
x = UBound(temp)
' redim each array with new rows.
ReDim FNArr(x)
ReDim LNArr(x)
ReDim AgeArr(x)
ReDim BloddArr(x)
For i = 0 To x
' split each line by semicolon sign
temp2 = Split(temp(i), ";")
' write each data to proper arrays
FNArr(i) = temp2(0)
LNArr(i) = temp2(1)
AgeArr(i) = temp2(2)
BloddArr(i) = temp2(3)
Next i
End Sub
Any help will be appreciated.
Thank you.