I have a text file Sample.txt with that contains thousands of records. See below. I have created vbscript that accept input box for the cut-off record. In this example I inputted 10005 as the cut-off record. The script will then read all records after the cut-off record, in this case starting at 10006 down to 10010, then write to a new text file with the current date as file name like 20180920.txt
10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010
Expected output:
10006 10007 10008 10009 10010
Sample script but not finished in writing the new file.
Dim Lastrecord
Dim IsFound, IsFound2
Dim CurrentDate
Const ForReading = 1
Set wShell = CreateObject("WScript.Shell")
Set oExec = wShell.Exec("mshta.exe ""about:<input type=file id=FILE><script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>""")
sFileSelected = oExec.StdOut.ReadLine
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(sFileSelected)
Set objFile1 = objFSO.OpenTextFile(objFSO.GetAbsolutePathName(objFile), ForReading)
CurrentDate = Replace(Date, "/", "")
Lastrecord = InputBox("Last Last Record:")
IsFound = 0
IsFound1 = 0
Do Until objFile1.AtEndOfStream
strLine = objFile1.ReadLine
If Trim(strLine) = Trim(LastRecord) Then
IsFound = 1
Exit Do
End If
Loop
objFile1.Close
WScript.Echo strLine
WScript.Echo Trim(Lastrecord)
-------------------I have completed the script, see below credit to @Ansgar Wiechers.
Dim Lastrecord
Dim IsFound, IsFound2
Dim CurrentDate
Const ForReading = 1
Set wShell=CreateObject("WScript.Shell")
Set oExec=wShell.Exec("mshta.exe ""about:<input type=file id=FILE><script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>""")
sFileSelected = oExec.StdOut.ReadLine
CurrentDate = Year(NOW) & Right("00" & Month(NOW), 2) & Right("00" & Day(NOW), 2) & Right("00" & Hour(NOW), 2) & Right("00" & Minute(NOW), 2) & Right("00" & Second(NOW), 2)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(sFileSelected)
Set objFile1 = objFSO.OpenTextFile(objFSO.GetAbsolutePathName(objFile), ForReading)
Lastrecord = InputBox("Last Last Record:")
IsFound = False
Set outFile = objFSO.CreateTextFile(objFSO.GetParentFolderName(objFile) & "\" & CurrentDate & ".DAT", True)
Do Until objFile1.AtEndOfStream
strLine = objFile1.ReadLine
If IsFound Then outFile.WriteLine strLine
If Trim(strLine) = Trim(LastRecord) Then IsFound = True
Loop
Wscript.Echo "New file created successfully at: " & objFSO.GetParentFolderName(objFile) & "\" & CurrentDate & ".DAT"
outFile.Close
objFile1.Close