Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to get the Next line after

Status
Not open for further replies.

ddrafts

IS-IT--Management
Dec 26, 2002
119
0
0
US
This script works like we want but we want to include the next in the output to include the next line. I'm not sure hot to proceed. Any help would be great.

Const ForReading = 1

Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.Pattern = "\d{9}"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\new4.txt", ForReading)
strSearchString = "049403900"
objFile.Close

Set colMatches = objRegEx.Execute(strSearchString)

If colMatches.Count > 0 Then
strMessage = "The Number was found at:" & vbCrlf
For Each strMatch in colMatches
strMessage = strMessage & strMatch.Value & " (character position " & _
strMatch.FirstIndex & ")" & vbCrLf
Next
End If

Wscript.Echo strMessage
 
But your script does not make any use of data stored in the file! strSearchString is assigned, not from the file. Maybe this may give you essential ingredients.
[tt]
Const ForReading = 1

Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.Pattern = "\d{9}"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\new4.txt", ForReading[blue],true[/blue])
[blue]do while not objFile.atEndOfStream[/blue]
[red]'[/red]strSearchString = "049403900"
[blue]strSearchString=objFile.readline[/blue]
[red]'[/red]objFile.Close

Set colMatches = objRegEx.Execute(strSearchString)

If colMatches.Count > 0 Then
strMessage = "The Number was found at:" & vbCrlf
For Each strMatch in colMatches
strMessage = strMessage & strMatch.Value & " (character position " & _
strMatch.FirstIndex & ")" & vbCrLf
Next
End If
[blue]loop
objFile.close
set objFile=nothing
set objFSO=nothing
[/blue]
Wscript.Echo strMessage
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top