将类的实例从.txt添加到列表框的实例visual basic

新的visual basic。我试图从csv文件中读取数据,将其拆分,然后仅在索引(0)处取值,并将它们全部添加到列表框中。这是我得到的。任何建议,我会很感激。将类的实例从.txt添加到列表框的实例visual basic

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 

Dim data() As String

Dim initFileContents() As String = IO.File.ReadAllLines("MembershipPhone.txt")

data = initFileContents.First.Split(","c)

name = data(0)

phone = data(1)

ListBox1.Items.Add(name)

TextBox1.Text = name

TextBox2.Text = phone

End Sub

当然这只会增加第一个实例。我需要C++等同于“对数据的每一行。”

回答:

只需使用一个for循环遍历()的返回ReadAllLines行:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 

Dim data() As String

For Each line As String In IO.File.ReadAllLines("MembershipPhone.txt")

data = line.Split(","c)

Name = data(0)

phone = data(1)

ListBox1.Items.Add(Name)

TextBox1.Text = Name

TextBox2.Text = phone

Next

End Sub

以上是 将类的实例从.txt添加到列表框的实例visual basic 的全部内容, 来源链接: utcz.com/qa/263675.html

回到顶部