PC Review


Reply
Thread Tools Rate Thread

Code to read file in reverse fast line by line

 
 
ChristopherL
Guest
Posts: n/a
 
      30th Sep 2008
Hello,

Does anyone have code that will show me how to read a file in
reverse from the end of the file towards the beginning of the file. I
have to find out if an exact phrase such as "the morning brings
another day exists in a file. I am planning on using "Instr" to do
this.

I do not want to use FileSearch's "keyword" search capability
because blanks in the phrase causes too many matches. I.E.: FileSearch
will say a file has the phrase if the file has the words all over the
place in a large file!

Thank you,
Chris
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      1st Oct 2008

A bit more clarification, especially "file in reverse"
I might assume that you mean you want to look in the last sheet, by
location, first.?????
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"ChristopherL" <(E-Mail Removed)> wrote in message
news:2f7d0145-983c-4ad9-a8a7-(E-Mail Removed)...
> Hello,
>
> Does anyone have code that will show me how to read a file in
> reverse from the end of the file towards the beginning of the file. I
> have to find out if an exact phrase such as "the morning brings
> another day exists in a file. I am planning on using "Instr" to do
> this.
>
> I do not want to use FileSearch's "keyword" search capability
> because blanks in the phrase causes too many matches. I.E.: FileSearch
> will say a file has the phrase if the file has the words all over the
> place in a large file!
>
> Thank you,
> Chris


 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      1st Oct 2008
If so, try this

Sub lookinreverse1()
what = "the morning brings another day"

num = Sheets.Count
'MsgBox num
On Error Resume Next
For i = num To 1 Step -1
With Sheets(i)
ma = .Cells.Find(what, LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext).Address
If ma > 0 Then
MsgBox Sheets(i).Name & ma
Exit Sub
End If
End With
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Don Guillett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> A bit more clarification, especially "file in reverse"
> I might assume that you mean you want to look in the last sheet, by
> location, first.?????
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "ChristopherL" <(E-Mail Removed)> wrote in message
> news:2f7d0145-983c-4ad9-a8a7-(E-Mail Removed)...
>> Hello,
>>
>> Does anyone have code that will show me how to read a file in
>> reverse from the end of the file towards the beginning of the file. I
>> have to find out if an exact phrase such as "the morning brings
>> another day exists in a file. I am planning on using "Instr" to do
>> this.
>>
>> I do not want to use FileSearch's "keyword" search capability
>> because blanks in the phrase causes too many matches. I.E.: FileSearch
>> will say a file has the phrase if the file has the words all over the
>> place in a large file!
>>
>> Thank you,
>> Chris

>


 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      1st Oct 2008
Do you means reverse by Row or Char.acters.

For Rows add numbers to an auxilary column and then sort decreasing on th
eauxilary column. Put 1 in row 1 and 2 in row 2. Then highlight both cells
and pull down the little square box in the bottom right corner of the
highlighted cells to number al the rows. Then sort on this new row




To read a file backward by characters use ReadAll to read the entire file
into a variable. then pull the characters out of the string backward like
below.



Const ReadFile = "c:\temp\event.txt"

Const ForReading = 1, ForWriting = 2, _
ForAppending = 3

Set fs = CreateObject("Scripting.FileSystemObject")
Set fin = fs.OpenTextFile(ReadFile, _
ForReading, TristateFalse)
Data = fin.readall

for i = len(Data) to 1 step -1
MyChar = mid(Data,i,1)
next i


"Don Guillett" wrote:

>
> A bit more clarification, especially "file in reverse"
> I might assume that you mean you want to look in the last sheet, by
> location, first.?????
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "ChristopherL" <(E-Mail Removed)> wrote in message
> news:2f7d0145-983c-4ad9-a8a7-(E-Mail Removed)...
> > Hello,
> >
> > Does anyone have code that will show me how to read a file in
> > reverse from the end of the file towards the beginning of the file. I
> > have to find out if an exact phrase such as "the morning brings
> > another day exists in a file. I am planning on using "Instr" to do
> > this.
> >
> > I do not want to use FileSearch's "keyword" search capability
> > because blanks in the phrase causes too many matches. I.E.: FileSearch
> > will say a file has the phrase if the file has the words all over the
> > place in a large file!
> >
> > Thank you,
> > Chris

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to store/read listbox items in a text file line by line (with line break) ? kimiraikkonen Microsoft VB .NET 6 2nd Nov 2007 05:27 PM
Fast file access reading text file line per line Volker Jobst Microsoft VB .NET 4 23rd Jun 2004 11:23 AM
Re: how to read an open sequential file line by line? Herfried K. Wagner [MVP] Microsoft VB .NET 0 21st May 2004 08:18 PM
Re: how to read an open sequential file line by line? Armin Zingler Microsoft VB .NET 0 21st May 2004 08:01 PM
HOWTO: Read a LARGE file, line by line backwards?? tor Microsoft C# .NET 1 13th Oct 2003 11:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:19 AM.