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

Reading Files in VBScript

Status
Not open for further replies.

EzehM

Programmer
Feb 27, 2003
86
GB
Please I need some help, I am pretty new to VBScript, I have the following file, and I need to read the last line of this file, to extract bytes 12 – 18. Each line in this file is terminated with <cr>and <lf>.

How can I read the last line into a variable?

An example of the file (called res.txt) is

Erot4959584848432030jfjrurur<cr><lf>
Dheyreoew9238384040430940059939393<cr><lf>
3749qwye7383373494392830403028384302ujw8932303<cr><lf>


Thanks in advance

 
set fso = create(&quot;scripting.filesystemobject&quot;)
set oFile = fso.openTextFile(&quot;filepath/filename&quot;,1)

do while not oFile.atEndOfStream
lastLine = oFile.readLine
loop

'lastLine now holds the last line of text....



Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
I tried this before posting the message. You code, just like mine, returns a line that contains <cr><lf>

What I need is to be able to read the line just above it.
Thanks.

i.e the file is like this: (sorry for my misinformation)
Erot4959584848432030jfjrurur<cr><lf>
Dheyreoew9238384040430940059939393<cr><lf>
3749qwye7383373494392830403028384302ujw8932303<cr><lf>
<cr><lf>
 
do while not oFile.atEndOfStream
previousLine = lastLine
lastLine = oFile.readLine
loop


'now &quot;previousLine&quot; will hold your value...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top