把一个文本里的每一行都存到一个数组里,行数不定.
不知道用动态数组还是 SPILT函数,
怎么能把字符串数组变成整形的 好用来计算
如果不用全部取出来的话,用动态数组一行一行读,读够需要的,exit DO 跳出,如果全部都得用话,那split还简单点追问
哪怎么将整个文本赋给一个字符串,再用split分开啊
追答Private Sub Form_Load()
'引用 Microsoft Scripting Runtime
Dim fso As New FileSystemObject, fil1 As File, ts As TextStream
Dim a() As String
Set fil1 = fso.GetFile("c:\t.txt")
' 读取文件的内容。
Set ts = fil1.OpenAsTextStream(ForReading)
s = ts.Readall
a = Split(s, vbCrLf)
MsgBox s
MsgBox a(UBound(a)) '这里显示数组最后一个内容
ts.Close
End Sub
这样啊 我用open半天没弄出来
还有
a = Split(s, vbCrLf)
For Each i In a
If Trim(i) " " Then
i = CInt(i)
End If
Next
想把a全换成int型的 怎么说i = CInt(i)这句不匹配啊
Dim shu() As Long
ReDim shu(UBound(a))
For n = 0 To UBound(a)
If Trim(a(n)) "" Then
shu(n) = CInt(Trim(a(n)))
End If
Next