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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read the last 12 lines of a large text file 1

Status
Not open for further replies.

alepore

MIS
Jun 25, 2001
27
US
I am new to scripting and I need some direction/help. I have a large text file and I want to only email the last 12 lines of the text file. Currently, I do a ReadAll and put that into the body of the email and send it off. Any help will be appreciated.

Option Explicit
Dim FsoObject
Dim OpenText
Dim Answer, ReadText, objEmail
Dim wn, fs, ws
Set wn = WScript.CreateObject("WScript.Network")
Set fs = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("WScript.Shell")
Set objEmail = CreateObject("CDO.Message")
Set FsoObject=wscript.createobject("scripting.filesystemobject")

Set ReadText=FsoObject.OpenTextFile("c:\textfile.txt", 1, "True")
Answer=ReadText.ReadAll

objEmail.From = "alepore@myemail.com"
objEmail.To = "alepore@myemail.com"
objEmail.Subject = "Test Subject"
objEmail.Textbody = Answer
objEmail.Configuration.Fields.Item (" = 2
objEmail.Configuration.Fields.Item (" = "mail.myemail.com"
objEmail.Configuration.Fields.Item (" = 25
objEmail.Configuration.Fields.Update
objEmail.Send
 
Hello alepore,
Code:
'after the Answer line
set ReadText=nothing
set FsoObject=nothing
aAnswer=split(Answer,vbcrlf)
sTrimAnswer=""
for i=ubound(aAnswer)-12+1 to ubound(aAnswer)-1
    sTrimAnswer=sTrimAnswer & aAnswer(i) & vbcrlf
next
sTrimAnswer=sTrimAnswer & aAnswer(ubound(aAnswer))
Answer=sTrimAnswer   '<<<the desired trimmed down answer
'followed by objEmail etc...
regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top