VB从文本文件读取直接赋值给二维数组?

文本文件中就25列,5行

dim a
dim b
dim z(24,4)
dim c,str as string
open app.apth & "\X.txt" for input as #1
do while not eof(1)
line input#1,c
str=str & c
loop
b=Split(str,vbcrlf) '取每一行的数据,共五行,所以一维数组b有五个元素,最大下标为4

for i=0 to ubound(b)
a=split(b(i)," ")

'对于每一个b的元素,取b中数据到a数组中,25列,所以数组a最大下标为24。

for j=0 to ubound(a)
z(i,j)=a(j)
next i
next i

'z(i,j)就是所得的二维数组
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-08-28
split
第2个回答  2009-08-28
每行的分隔符是什么

VB从文本文件读取直接赋值给二维数组?
next i 'z(i,j)就是所得的二维数组

...帮忙啊:vb 中如何从txt文件中将数据读取出来并赋值给二维数组?
假设点击命令按钮Command1就将e:\\aa.txt读入p(i,j)中,Command1的代码如下(你照复制就是):Private Sub Command1_Click()Dim StrLine As String, a() As String, p(11, 5) As String, i As Long, j As Long Open "e:\\aa.txt" For Input As #1 For j = 0 To 5 Do Until EOF...

VB从文本文件读取数据并赋给赋值给变量及二维数组
5421. 235 ,5257. 232 ,117. 4712(也就是文件的前2行的数值)分别赋值给n, ta, xa, ya, xb, yb, tb 其中第一行第一个数5,意思是第三行到最后一行一共5行,这个数是第三行到最后一行的行数对应的,我的意思是将第三行至最后赋给数组b(v), s(v)!根据我上边的数据这里v-1=5,...

vb读取txt数据到二维数组
1.读取文件,把整个内容读到一个字符串变量里(里边只有空格没有回车);2.把规矩的字符串分割到一维数组;3.把一维数组变成二维数组。

在vb中,如何把文本文档中的数据读入到二维数组中,并且使二维数组的下...
Private Sub Form_Click()Dim temp As String, str As String Dim w1 As Integer, w2 As Integer '维数 Dim a() As Integer, b() As Integer Dim i As Integer, j As Integer, k As Integer w1 = 0 w2 = 0 Me.Text1.Text = "矩阵的初始状态为:"+ vbCrLf Me.Text2.Text = "...

求关于vb怎么把文本框里输入的矩阵读入一个二维数组中保存下来_百度知 ...
楼主可参考如下代码:Dim i As Integer, j As Integer, x(4, 4) As Integer Dim s() As String Dim ss() As String s = Split(Text1.Text, Chr(13) & Chr(10))For i = 0 To 4 ss = Split(s(i))For j = 0 To 4 x(i, j) = Val(ss(j))Next Next ...

请问大神如何用VB将文本文件的数据存入二维数组
Dim Arr() As Double Dim num As Integer Private Sub Command1_Click()Dim tmpArr() As String, Arr1() As String Dim tmp As String, i As Integer Open "D:\\1.txt" For Input As #1 num = 0 Do Until EOF(1)Line Input #1, tmp If tmp <> "" Then tmpArr = Split(Replace...

vb 从文件读取数据到数组
我的data.txt中有25个用“,”分隔的数,要读入到二维数组mat中,下面是代码:Const N = 5 Const M = 5 Dim temp, mat(1 To 5, 1 To 5)Dim i, j Open "data.txt" For Input As #1 For i = 1 To N For j = 1 To M Input #1, temp \/data.txt中的数应该是字串型的,mat(...

VB.net 中,我想把TXT的数据文件导入到二维数组中,数据文件的格式是这...
很简单,代码如下:Dim f As String = My.Computer.FileSystem.ReadAllText("c:\\test.txt") '读取Strings.Replace(f, vbNewLine, ",") '替换回车符为逗号Dim a() As String = Split(f, ",") '按逗号分隔字符串,转换为字符串数组For i = 0 To a.Length - 1 '在立即窗口显示数组...

VBA批量导入文本文件,如何转换二维数组?
Filename = p & "\\" & f Open Filename For Input As #1 str = StrConv(InputB(LOF(1), 1), vbUnicode)Close #1 arr = Split(str, Chr(10)) '只会生成一维数组,如何变成二维数组录入到单元格中 ReDim brr(UBound(arr))For i = 0 To UBound(arr)brr(i) = UBound(Split(arr(i...

相似回答