Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel - find
Message
From
06/10/2004 08:57:38
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
06/10/2004 08:35:47
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Miscellaneous
Thread ID:
00948975
Message ID:
00949122
Views:
21
This message has been marked as the solution to the initial question of the thread.
>thanks for the tip, Cetin. I actually wouldn't need Excel at all if VFP did the following:
>
>Search a text file for a given word;
>Be able to scroll down or up from that position by a given number of rows (similar to the offset in excel)
>save the value on that line to a variable
>
>i spent a number of hours (who's kidding who - days) on getting foxpro to do this, and couldn't get it to work. excel offers all of these things.
>
>if you have a suggestion for the above, i would be very happy to hear it. thanks for your help.
>
>paul

If file is not a huge one, there are many and much faster ways in VFP. ie:

1) Assuming linecount fitting array limit 65000
lnLines = alines(arrLines, FileToStr('myFile.txt'))
for ix=1 to lnLines
 if atc(lcSearchText,arrLines[m.ix]) > 0 && Found line
    if m.ix + m.RowOffsett < m.lnLines && Check if offsett is in range
       ? arrLines[m.ix]
    endif
 exit
 endif
endfor
2) Assuming no line is longer than 1024 (memowidth limit)
set memowidth to 1024
lcFileContent = FileToStr(lcFileName)
lnFoundAtLine = atcline(lcSearchStr, lcFileContent)
if m.lnFountAtLine + m.lnOffsett <= memlines(m.lcFileContent)
  ? mline(m.lcFileContent, m.lnFountAtLine + m.lnOffsett) && Might also utilize 3rd param
endif
3) Assuming no line is longer than 255:
create cursor myTemp (myLine c(255))
append from (lcFileName) type SDF
locate for atc(m.lcSearchStr,myLine) > 0
if !eof()
   skip m.nOffsett
   ? myLine
endif
4) Lowlevel - assuming no line is over 8192
handle = fopen(lcFilename)
do while !feof()
  if atc(m.lcSearched, Fgets(handle,8192)) > 0
     for ix=1 to m.nOffsett
        if !feof()
           Fgets(handle,8192)
        endif
     endfor
     if !feof()
       ? fgets(handle,8192)
     endif
    exit
  endif
enddo
etc etc. None is tested, nOffsett adjusment isn't made. Yet there are other methods that excel simply wouldn't be able to even show (at least not with my hardware).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform