第1个回答 2009-04-17
Private Sub Command1_Click()
Dim i As Integer, j As Integer, s As String, FileName As String
Dim AA() As String, BB() As Byte, CC() As String, DD() As String
FileName = "c:\1.txt" '请根据实际修改
If Dir(FileName) = "" Then Exit Sub
i = FreeFile
ReDim BB(FileLen(FileName) - 1) '定义临时数组
Open FileName For Binary As #i
Get #i, , BB '读取文本文件数据到临时数组
Close #i
s = StrConv(BB, vbUnicode)
AA = Split(s, vbNewLine)
ReDim CC(UBound(AA), 1 To 8) '定义输出数组
For i = 0 To UBound(AA)
s = AA(i)
s = Replace(s, " ", " ")
DD = Split(s, " ")
For j = 1 To IIf(UBound(DD) <= 8, UBound(DD), 8)
CC(i, j) = DD(j) '把临时数组的元素写入输出数组中
Next
Next
End Sub
第2个回答 2009-04-17
Private Sub Command1_Click()
Dim i As Integer, j As Integer, str1 As String, strfName As String
Dim lTmp, strData() As String
strfName = "c:\1.txt" '请根据实际修改
If Dir(strfName) = "" Then Exit Sub
Open strfName For Input As #1
Do While (Not EOF(1))
Line Input #1, str1
lTmp = Split(Trim(str1), " ")
i = i + 1
ReDim Preserve strData(0 To 7, 1 To i)
For j = 0 To 7
strData(j, i) = Trim(lTmp(j)) '如果是数字,strData为相应数据类型,值用Val函数转化
Debug.Print strData(j, i); " ";
Next j
Debug.Print
Loop
Close
End Sub
第3个回答 2009-04-16
dim strline as string
dim a()
dim i as integer
open app.path +"\1.txt for input as #1
do until eof(#1)
i=i+1
line input #1,strline
b= split(strline," ")
redim preserve a(i*8)
for cnt=0 to 7
a((i-1)*8+cnt)=b(cnt)
next cnt
loop本回答被提问者采纳