CodeItBetter Programming Another VB Programming Blog

How to Extract each and every word individually from a text file

Posted on October 24, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'Text File Handling - How to Extract each and every word individually from a text file
Public Sub ExtractWords(ByVal strFilePath As String, ByVal intHeaderLines As Integer)
    Dim strTxt As String
    Dim strLines() As String
    Dim strWords() As String
    Dim intCount As Integer
    Dim iCount As Integer
 
    On Error GoTo ExtractWords_Error
 
    'Open the text file
    Open strFilePath For Input As #1
    'load the text file in strTxt variable
    strTxt = Input(LOF(1), 1)
    'close the text file
    Close #1
 
    'Split the line by crlf
    strLines = Split(strTxt, vbCrLf)
 
    For intCount = LBound(strLines) To UBound(strLines)
        'To ignore first 6 header lines
        If Not intCount < intHeaderLines Then
            'Split each line into words
            strWords = Split(strLines(intCount))
            For iCount = LBound(strWords) To UBound(strWords)
                Debug.Print strWords(iCount)
            Next iCount
        End If
    Next intCount
 
    On Error GoTo 0
    Exit Sub
 
ExtractWords_Error:
    If Err.Number <> 0 Then Call MsgBox(Err.Number & " " & Err.Description)
    Err.Clear
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.