Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can this code be faster?
Message
From
19/08/2003 20:13:41
 
 
To
19/08/2003 16:48:44
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00821524
Message ID:
00821633
Views:
27
This message has been marked as the solution to the initial question of the thread.
Tracy,

If that works, it can probably be made even shorter.
AT(" ",STRTRAN(insured.po_name," ","*",1)) > 0
Should always be false, so the first iif() condition can never be met since you are checking for the position of a space in a string where you have replaced all spaces with asterisks. Therefore, execution will always land on the the second iif(), so the first one could be eliminated.

This should return the same result with only one IIF().
xreturn=BETWEEN(UPPER(LEFT(insured.po_name,;
  	IIF(AT("*",STRTRAN(insured.po_name," ","*",1))> 0,AT("*",STRTRAN(insured.po_name," ","*",1))-1,;
        LEN(insured.po_name)))),;
	UPPER(xfrom),UPPER(xto))
Or am I missing something?

>Actually it only passed the first record of SMITH III*JAMES. But with a slight modification, it works great!
>Thanks!
>
>		xreturn=BETWEEN(UPPER(LEFT(insured.po_name,;
>	   	IIF(AT(" ",STRTRAN(insured.po_name," ","*",1)) > 0,AT(" ",STRTRAN(insured.po_name," ","*",1))-1,;
>        	IIF(AT("*",STRTRAN(insured.po_name," ","*",1))> 0,AT("*",STRTRAN(insured.po_name," ","*",1))-1,;
>        	LEN(insured.po_name))))),;
>			UPPER(xfrom),UPPER(xto))
>
>
>>May not be faster but is is shorter, possibly more convoluted, but I think it does the same thing. If you are trying to determine if the last name is between 2 values ignoring case and last name will be always be followed by space or * or will be only the last name.
>>
>>
>>*!* Assumes set exact on
>>RETURN BETWEEN(UPPER(LEFT(insured.po_name,;
>>        IIF(AT(" ",insured.po_name) > 0,AT(" ",insured.po_name)-1,;
>>        IIF(AT("*",insured.po_name)> 0,AT("*",insured.po_name)-1,;
>>        LEN(insured.po_name))))),;
>>	UPPER(xfrom),UPPER(xto))
>>
>>
>>
>>
>>>We are searching records for any condition using a from and to condition. Records are stored like so:
>>>
>>>SMITH*JAMES
>>>SMITH III*MICHAEL
>>>SMITH JR*JOHN
>>>SMITHERMAN*PETER
>>>
>>>I must account for the user entering from: SA to: SMITH or from: SMITH to: SMITH, or from: A to: Z, etc. SMITH to SMITH should NOT include SMITHERMAN...
>>>
>>>The below code works (If exact is on and near is off), but can it be faster?
>>>
>>>
>>>xreturn=.T.  && include this record, .f. if record does not meet condition
>>>  IF !EMPTY(xfrom) OR !EMPTY(xto)
>>>    IF ALLTRIM(UPPER(xfrom))=ALLTRIM(UPPER(xto))
>>>      IF ALLTRIM(UPPER(xfrom)) $ LEFT(UPPER(LEFT(STRTRAN(insured.po_name," ","*",1),;
>>>          AT("*",STRTRAN(insured.po_name," ","*",1))-1)),LEN(ALLTRIM(UPPER(xfrom)))) ;
>>>          .AND. UPPER(LEFT(STRTRAN(insured.po_name," ","*",1),;
>>>          AT("*",STRTRAN(insured.po_name," ","*",1))-1));
>>>          <= UPPER(ALLTRIM(xto))
>>>        ? po_name+ "    YES a match"
>>>        xreturn = .T.
>>>      ELSE	&& not a match
>>>        ? po_name+"    NO not a match"
>>>        xreturn = .F.
>>>      ENDIF
>>>    ELSE
>>>      *--TCH 08/13/2003 * for  SMITH III*JAMES, etc
>>>      *IF !BETWEEN(UPPER(LEFT(insured.po_name,AT("*",insured.po_name)-1)),xfrom,xto)
>>>      IF !BETWEEN(UPPER(LEFT(STRTRAN(insured.po_name," ","*",1),;
>>>          AT("*",STRTRAN(insured.po_name," ","*",1))-1)),xfrom,xto)
>>>        xreturn = .F.
>>>      ENDIF
>>>    ENDIF
>>>  ENDIF
>>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform