0
Sub DUE()

    Dim strBuffer As String
    Dim strContents() As String
    Dim I As Long

    ReDim strContents(0)
    Erase strContents()

    Close #1
    Open "C:\TEST\28-06-2013.TXT" For Input As #1
    strBuffer = Input(LOF(1), 1)
    Close #1

    strContents = Split(strBuffer, vbCrLf)

    For I = LBound(strContents) To UBound(strContents)
        'Debug.Print strContents(I)
    Next I

End Sub

内存不足的问题!!!!

缓冲txt文件时。大约 256 mb 1.500.xxx 行。每条线的长度固定为 132。

4

1 回答 1

1

最好Line Input改用:

Sub DUE()
    Dim I As Long
    Dim strContents() As String
    Open "C:\TEST\28-06-2013.TXT" For Input As #1
        Do Until EOF(1)
            Redim Preserve strContents(i)
            Line Input #1, strContents(i)
            'Debug.Print strContents(i)
            I = I + 1
        Loop
    Close #1
End Sub

然后您可以从 访问每一行strContents

另外值得注意的是:

ReDim strContents(0)
Erase strContents()

这不太合适。改用我的线:

Dim strContents() As String

编辑:

或者更好的是,在每一行上做你需要做的事情,不要费心将它存储在里面strContents,就像这样:

Sub DUE()
    Dim S As String
    Open "C:\TEST\28-06-2013.TXT" For Input As #1
        Do Until EOF(1)
            Line Input #1, S
            'Debug.Print S
        Loop
    Close #1
End Sub
于 2013-08-20T13:28:44.453 回答