可能重复:
Error switch CVS text file item when selecting listbox item in Visual Basic
我正在尝试将文本文件中的行导入列表框,但是收到此错误消息:
- 附加信息:索引超出了数组的范围.--
文本文件中的信息如下:
Ball,Krystal,F,1981
Banks,Robin,F,1988
Burgher,Hamilton,M,1980
Early,Brighton,M,1989
Hedd,MT,M,1960
Hogg,Ima,F,1953
Knapp,Anita,F,1970
Overnout,Roger,M,1968
Psito,Arnie,M,1962
Teak,Anne,F,1939
我的代码如下:
Dim names() As String = IO.File.ReadAllLines("Info.txt")
Dim query = From line In names
Let data = line.Split(","c)
Let lName = data(0)
Let fName = data(1)
Let gender = data(2)
Let yOB = CInt(data(3))
Select lName, fName, gender, yOB
For Each person In query
lstLNames.Items.Add(person.lName)
Next
有人可以让我知道什么是错的。提前谢谢。