Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Searching through all application directory...
Message
From
18/10/2000 18:00:38
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00430305
Message ID:
00431205
Views:
25
>>In the meantime I already created a simple program, based on Ed's idea. The only problem in the following code, that instead of particular string in Init method it prints the whole form's code. Also note, that I changed incorrect string to Matches=oReg.Execute(ThisScx.Methods) (checked Help on VBScript.RegExp - I think Ed made a little code mistake in purpose :))
>>
>
>Early AM can make writing code off the top of your head a bit harder. Especially if you don't preview the code. I guess I'll start leaving the implementation as an exercise for the reader and let you guys figure it out fr yourself; I already know how to use this stuff...
>

I'm going in and removing the extraneous operations; I'll explain in-line. Equally important, I'm going to explain the unobvious things that make this an interesting example/demo of the tools:

>>Here is a program:
>>
>>********************************************************************
>>*  Description.......: SearchScx - searches all SCX files for sSearchString in MethodToSearch
>>*  Calling Samples...:
>>*  Parameter List....: pcSearchString, pcMethodToSearch
>>*  Created by........: Ed Rauh
>>*  Modified by.......: Nadya Nosonovsky 10/18/2000 03:01:23 PM
>>********************************************************************
>>lparameters pcSearchString, pcMethodToSearch
>>if vartype(pcSearchString)'C'
>>     pcSearchString=upper("SetFocus")
>>else
>>     pcSearchString=upper(pcSearchString)
>>endif
>>if vartype(pcMethodToSearch)'C'
>>     pcMethodToSearch=upper("Init")
>>else
>>     pcMethodToSearch=upper(pcMethodToSearch)
>>endif
>>=GetAllFiles1('\redp\appl','scx') && Creates cursor filesADIR of all scx files
>>local oReg, lcTextString
>>oReg = createobject('VBScript.RegExp')
>>oReg.global = .t.
*
*  The .Global property tells the RegExp object to search for more than one
*  occurance of the pattern in the string
*
>>oReg.IgnoreCase = .t.
*
*  .IgnoreCase performs compares in a case - insensitive manner
*
>>oReg.pattern = 'PROCEDURE '+pcMethodToSearch+'([^\0]*)ENDPROC'
*
*  .Pattern is the heart of the object - it describes the regular expression to
*  search for.  Our pattern is the word "PROCEDURE" followed by a space, 
*  followed by the content of the variable pcMethodToSearch.  In a real life
*  situation, we'd want to parse pcMethodToSearch a character at a time, so
*  that if any of the special characters "\^$*+?.(){}|-," occurred, we'd force
*  them to be literals, so the string 'Mr. Smith-Jones' would be changed into
*  'Mr\. Smith\-Jones'.  Alternatively, we might work on the premise that the
*  user knows about regular expressions;  he could intentionally enter a
*  regular expression instead of a simple literal, eg '\w*_ACCESS' would get
*  all the _ACCESS methods.  The same core code for either behavior will
*  fit different users - it looks like a candidate for a class hierarchy
*
*  The balance of the expression is any number of non-null characters, followed
*  by the string 'ENDPROC'
*
>>#define CRLF chr(13)+chr(10)
>>lcTextString = ''
>>select FilesAdir && cursor with all scx files
>>scan
>>    if file(forceext(cFileName,'sct')) && Memo file is where
>>     use (cFileName) alias ThisSCX in 0 noupdate
>>     select ThisSCX
>>     scan for 'form ' $ lower(baseclass + ' ') and ! empty(Methods)
>>          Matches=oReg.Execute(ThisSCX.Methods)
*
*  This extracts all occurances of the regular expression contained within
*  the () scoping into a colection.  The collection has a Value, the match
*  string itself, StartPosition, the 1-indexed position of the match, and
*  Length, the length of the match
*
>>          for each oMatch in Matches
>>               if pcSearchString $ upper(oMatch.value)
>>                    lcTextString = lcTextString  + FilesAdir.cFileName+ ': ' +ThisSCX.ObjName + CRLF + ;
>>                         oMatch.value + CRLF + CRLF
*
*  We've recorded the name of the file, the name of the object in the file,
*  and the actual content of the method.  Setting flag doesn't do anything
*  that appears useful
*
>>                    replace flag with .t. in FilesAdir
>>               endif
>>          endfor && each match
>>     endscan  && each form rec in SCX
>>     use in ThisSCX
>>     endif
>>     select FilesAdir && safety meassure
>>endscan && each app dir
>>if len(lcTextString) > 0
>>     =strtofile(lcTextString,'Result.TXT')
>>     modi file 'Result.TXT'
>>endif
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform