Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Tony Vignone
  Where is Tony Vignone?
 St Augustine
 Florida - United States
 Tony Vignone
 To: Samir Ibrahim
  Where is Samir Ibrahim?
 Chekka
 Lebanon
 Samir Ibrahim
 Tags
Subject: RE: Name of a Variable
Thread ID: 227055 Message ID: 228821 # Views: 1 # Ratings: 0
Version: Visual FoxPro 9 Category: General VFP Topics
Date: Thursday, May 21, 2009 7:58:52 PM         
   


> >
> > Your solution is for this specific predicate. It won't work for a general one, like...
>
>
> :-)
>
> This function works for both predicate
>
>
> i = searchfor(@atext,1,[i<alen(atext) and ("$" $ atext(i+1) or "#" $ atext(i+1)) and "enemy" $ atext(i)])
> 
> i = searchfor(@atext,1,[i<alen(atext) and "$" $ atext(i+1) and "enemy" $ atext(i)])
> 

>
>
Function SearchFor(atext,nStartat,cPredicate)
> 	On Error *
>         nAnswer = 0
> 	For I = 1 to Alen(aText)
> 		If &cPredicate then 
> 		    nAnswer = I
> 		EndIf 
> 	Next I
>         Return nAnswer
> EndFunc 


Ok you replace the EVALUATE() - you are getting closer. But the array in the predicate and the index is NOT visible inside the function - they are LOCAL! Try this. cPredicate simply rings true for every line.
You assumed that the caller would always use atext and i as the names that are in the function. They MUST BE REPLACED with the names of the function parameters!
In your example, there is confusion between the local I in the function and the i in the predicate!

local j
local array atext(3)
atext(1) = "Now is the time for all to come to the aid of their country."
atext(2) = "We has met the enemy, and he is us!"
atext(3) = "You now have $12,456,89"

j = searchfor(@atext,1,[j<alen(atext) and ("$" $ atext(j+1) or len(atext(j+1)) > 20) and "enemy" $ atext(j)])
IF j <= alen(atext) THEN
   ?atext(j)
ELSE
   ?"NOT FOUND"
ENDIF


Function SearchFor(aArray,nStartat,cPredicate)
 	On Error *
         nAnswer = 0
 	For I = nStartat to Alen(aArray)
 		If &cPredicate then 
 		    nAnswer = I
 		EndIf 
 	Next I
    Return nAnswer
EndFunc


ENTIRE THREAD

Name of a Variable Posted by Tony Vignone @ 5/6/2009 4:05:35 PM
RE: Name of a Variable Posted by Tom Saddul @ 5/6/2009 4:22:19 PM
RE: Name of a Variable Posted by Tony Vignone @ 5/6/2009 4:57:45 PM
RE: Name of a Variable Posted by Tom Saddul @ 5/6/2009 5:37:24 PM
RE: Name of a Variable Posted by Tony Vignone @ 5/6/2009 5:43:49 PM
RE: Name of a Variable Posted by Tony Vignone @ 5/6/2009 5:58:58 PM
RE: Name of a Variable Posted by Tom Saddul @ 5/6/2009 6:19:08 PM
RE: Name of a Variable Posted by Tony Vignone @ 5/14/2009 3:19:11 PM
RE: Name of a Variable Posted by Tom Saddul @ 5/17/2009 10:09:28 AM
RE: Name of a Variable Posted by Tony Vignone @ 5/17/2009 7:31:52 PM
RE: Name of a Variable Posted by Tom Saddul @ 5/18/2009 8:09:44 AM
RE: Name of a Variable Posted by Tony Vignone @ 5/18/2009 3:52:23 PM
RE: Name of a Variable Posted by Tom Saddul @ 5/19/2009 3:41:37 PM
RE: Name of a Variable Posted by Tony Vignone @ 5/19/2009 4:02:11 PM
RE: Name of a Variable Posted by Tony Vignone @ 5/18/2009 6:20:29 PM
RE: Name of a Variable Posted by Samir Ibrahim @ 5/19/2009 6:56:28 PM
RE: Name of a Variable Posted by Tony Vignone @ 5/19/2009 9:10:40 PM
RE: Name of a Variable Posted by Samir Ibrahim @ 5/20/2009 10:21:14 AM
RE: Name of a Variable Posted by Tony Vignone @ 5/20/2009 6:34:39 PM
RE: Name of a Variable Posted by Tom Saddul @ 5/21/2009 1:52:57 AM
RE: Name of a Variable Posted by Tony Vignone @ 5/21/2009 7:33:39 PM
RE: Name of a Variable Posted by Samir Ibrahim @ 5/21/2009 10:35:02 AM
RE: Name of a Variable Posted by Tony Vignone @ 5/21/2009 7:58:52 PM
RE: Name of a Variable Posted by Samir Ibrahim @ 5/22/2009 11:04:13 AM
RE: Name of a Variable Posted by Tony Vignone @ 5/22/2009 3:07:38 PM
RE: Name of a Variable Posted by tushar @ 5/6/2009 6:10:53 PM