I am getting "out of memory" (run time error 7) error on ReDim Preserve myArr(totalAmou nt). When I put my mouse over this line it reads 65894. My text file has 780k lines (almost a meg.). Anything I can do to make this go away. I am trying to retrieve certain row from a large text file.
Code:
Private Sub cmdImportRow_Click() Dim myPath, myFile As String Dim myLine As Integer myPath = "\\server path\my folder\" myFile = myPath & "test.txt" myLine = 13 Me.Text5 = ExactLine2(myFile, myLine) End Sub Function ExactLine2(ByVal fileName As String, ByVal lineNumber As Long) As String ' Dim myArr() As String Dim totalAmount As Long Dim intFileHandle As Long Dim sLineIn As Variant ' 'Use FreeFile it is good pratice intFileHandle = FreeFile() ' 'Open the text file Open fileName For Input As #intFileHandle ' 'Do only while there is text While Not EOF(intFileHandle) ' 'Go through the text file and load it into sLineIn Line Input #intFileHandle, sLineIn ' 'Make sure we create a zero based array 'If totalAmount <> "" Then totalAmount = totalAmount + 1 'Else ' totalAmount = 0 'End If ReDim Preserve myArr(totalAmount) myArr(totalAmount) = sLineIn Wend ' 'This will obtain the line ExactLine2 = myArr(lineNumber) ' 'Clean up Close #intFileHandle ' End Function
Comment