如何用vb读取一个5列n行的数组,并且第一行是汉字
发布网友
发布时间:2024-10-23 22:41
我来回答
共1个回答
热心网友
时间:2024-10-24 15:01
朋友,问问题一定要详细。读数组,从哪里读?读了以后又怎么办?
提供一份代码,是从TXT文件里读取5列n行的数组,并显示在文本框里。无论是汉字还是数字都可以读取的。
Private Sub Command1_Click()
Dim s1 As String
Dim s2() As String
Dim S3() '用来存放读出来的数
Dim I As Long
Dim J As Long
Dim K As Long
I = 0
Open "数组.txt" For Input As #1
'读取数据放入二维数组S3里
Do While Not EOF(1)
Line Input #1, s1
ReDim Preserve S3(4, I)
s2 = Split(s1, ",")
For J = 0 To 4
S3(J, I) = s2(J)
Next J
I = I + 1
Loop
Close #1
'输出数组到文本框
K = UBound(S3, 2)
For J = 0 To K
For I = 0 To 4
Text1.Text = Text1.Text + S3(I, J) + ","
Next I
Text1.Text = Text1.Text & vbCrLf
Next J
End Sub
运行效果图:
提供源代码一份