供参考:
Dim NameList(300, 1) As String
Dim listCounts As Int16
Private Sub ReadNameFromText()
Dim fs As StreamReader
Dim oneLine As String
Try
fs = New StreamReader("namelist.txt") '在文件中存了员工号和姓名
oneLine = fs.ReadLine()
While (oneLine <> "")
SeparateName(oneLine)
oneLine = fs.ReadLine()
End While
fs.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub SeparateName(ByVal value As String)
Dim strValue As String
Dim strArray(1) As String
strValue = value
strArray = strValue.Split(vbTab) '将Tab分开的一行数据赋予一个数组
Private Sub ShowInfo(ByVal InfoFile As String, ByVal InfoCount As Integer, ByVal MidStr As String, ByVal TargetView As ListView)
Dim strInfo(InfoCount - 1) As String
Dim objReader As New StreamReader(InfoFile)
Dim sLine As String = ""
Dim i As Integer
Dim lviInfo As ListViewItem
Dim c As Integer
Dim t As Integer
Do
sLine = objReader.ReadLine()
c = 0
t = 1
If Not sLine Is Nothing Then
For i = 1 To Len(sLine+MidStr)
If Mid(sLine+MidStr, i, 1) = MidStr Then
strInfo(c) = Mid(sLine+MidStr, t, i - t)
t = i + 1
c = c + 1
End If
Next i
lviInfo = New ListViewItem(strInfo)
TargetView.Items.Add(lviInfo)
End If
Loop Until sLine Is Nothing