0

I've been trying to check if a given txt file has lines that start with a particular word. I then want to count the number of lines that start with that word. Though I can't quite get it right, I do think I'm somewhat close with the check. Any and all help are much appreciated! Here's my code so far

.Pattern = "(\nC_PIN\s)(\b\d\b\s)"
.Global = True
Set objFil3 = objFSO.OpenTextFile(inFileName)
If objFil3.IsMatch(inFileName) Then
 MsgBox "File OK"

Else: MsgBox "Wrong file type chosen. Please check directory"
End If
4

1 回答 1

1

罗伯特,.ReadLine在你的对象变量上使用方法。

Dim numLines as Long: numLInes = 0
Dim strSearch as string '## the value you're searching for
strSearch = "Steve!"    '## MOdify as needed
Do While Not objfil3.AtEndofStream
    If Left(objfil3.ReadLine, Len(strSearch)) = strSearch Then
        numLines = numLines + 1
    Else:

    End If
Loop
    MsgBox objFil3 & " contains " & numLines & " beginning with " & strSearch
于 2013-07-29T15:08:20.313 回答