当前位置:编程学习 > C#/ASP.NET >>

Visual Basic.NET(将文本文件导入数组)

答案:开始时引用
Imports System.IO

按钮的Click事件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'打开目标文件(文件流)
Dim myFs As New FileStream(Application.StartupPath & "\a.txt", FileMode.Open, FileAccess.Read)
'读文件
Dim r As New StreamReader(myFs)
Dim i As Integer
Dim myLine, tempStr As String
'创建数组,接收文件数据
Dim myLineStr(), a(100), b(100) As String
Dim c(100) As Integer
i = 0
myLine = r.ReadLine
Do While Not (myLine Is Nothing)
myLineStr = myLine.Split(",")
a(i) = myLineStr(0)
b(i) = myLineStr(1)
c(i) = myLineStr(2)
i += 1
Loop
End Sub


上一个:让你的VB程序支持多国语言的切换
下一个:通过WMI获得硬盘和CPU的物理序列号(VB.net)

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,