TPE

http://bayanbox.ir/view/263405954590585756/2mobile.png

Tavvafi@gmail.com


≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

Sub TextFileToArray(ByRef aText As Variant, ByVal sTextFile As String)
' Reads a text file into an array, one line per array element

    Dim FileNum As Integer
    Dim Buffer As String
    ReDim aText(1 To 1)

    FileNum = FreeFile()
    Open sTextFile For Input As FreeFile
    While Not EOF(FileNum)
        Line Input #FileNum, Buffer
        ' Ignore blank lines
        If Trim(Buffer) <> "" Then
            'Call AddAPhrase(aText, Buffer)
            aText(UBound(aText)) = Buffer
            ReDim Preserve aText(1 To UBound(aText) + 1)
        End If
    Wend
    Close #FileNum

    ' This leaves the array with one bogus empty record at end so
    ReDim Preserve aText(1 To UBound(aText) - 1) As String

End Sub

And you can use this routine to test the one above:

Sub TestThis()
    Dim sTextFile As String
    Dim aText() As String
    Dim x As Long

    sTextFile = "C:\TEMP\TEXT.TXT"

    Call TextFileToArray(aText, sTextFile)

    For x = LBound(aText) To UBound(aText)
        Debug.Print aText(x)
    Next

End Sub