Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Correct Syntax For 'AND' & 'OR' with Locate Command
Message
De
20/04/2018 08:03:46
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
25/03/2018 16:26:58
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01658981
Message ID:
01659555
Vues:
51
You don't have parentheses, and AND taking precedence your code reads like:
LOCATE FOR  LEFT(STREXTRACT(POS,'(',')'),10)= '- One Time' OR ;
 LEFT(STREXTRACT(POS,'(',')'),23)='- Account Level Charges' OR ; 
 ( LEFT(STREXTRACT(POS,'(',')'),23)='Itemized Calls' AND Pageno=(I+1) )
That makes PageNo check effectively related to last 'Itemized Calls'.

You could correct that changing the parentheses location like:
LOCATE FOR (  LEFT(STREXTRACT(POS,'(',')'),10)= '- One Time' OR ;
 LEFT(STREXTRACT(POS,'(',')'),23)='- Account Level Charges' OR ; 
 LEFT(STREXTRACT(POS,'(',')'),23)='Itemized Calls') AND Pageno=(I+1) 
However, you are doing a bigger mistake which not only newbies but experts do as well and that is, you are not prefixing your memory variables with mdot (you are doing that correctly for m.lnPageCount but that is more important when you are using one letter variables in the range A-J). Correct your code:
LOCATE FOR (  LEFT(STREXTRACT(POS,'(',')'),10)= '- One Time' OR ;
 LEFT(STREXTRACT(POS,'(',')'),23)='- Account Level Charges' OR ; 
 LEFT(STREXTRACT(POS,'(',')'),23)='Itemized Calls') AND Pageno=(m.I+1) 
Next, you could simplify your code a bit. You don't need to count how long is your string to compare. If set exact is off (VFP default), = acts as starts with:
LEFT(STREXTRACT(POS,'(',')'),10)= '- One Time'

STREXTRACT(POS,'(',')')= '- One Time'
Would both mean the same thing.

Next, instead of using For ... endfor, locate and if found(), you can further simplify it into a simple Scan ... Endscan loop:
Scan For Between(PageNo, 2, m.lnpagecount) And ;
		( Strextract(POS,'(',')')= '- One Time' Or ;
		STREXTRACT(POS,'(',')')='- Account Level Charges' Or ;
		STREXTRACT(POS,'(',')')='Itemized Calls' )

	**Do Something based on certain conditions

Endscan
>I am using the following command to Locate something in a Table
>
>
>For I=2 to m.lnpagecount
>LOCATE FOR  LEFT(STREXTRACT(POS,'(',')'),10)= '- One Time' OR ;
>LEFT(STREXTRACT(POS,'(',')'),23)='- Account Level Charges' OR ; 
>LEFT(STREXTRACT(POS,'(',')'),23)='Itemized Calls' AND Pageno=(I+1)
>
>IF Found()
>**Do Something based on certain conditions
>Endif
>
>I=I+1
>Endfor
>
>
>Since the value of I is 2 initially my cursor should Locate for page 3 initially and each time it should locate the data in Pageno 4 , 5 , 6 etc as the value of I increases by 1 each time.
>
>But Every Time cursor is halting on Pageno=2 even though the value if I is increasing to 3,4,5 etc. What is the problem ?
>
>
>What will be the proper syntax to use this.
>
>Thanks
Ç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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform