Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scan loop

Status
Not open for further replies.

FoxStudent

Technical User
Feb 24, 2000
85
GB
How do I set up the scan condition in such a way that if I do not enter all search fields, that it will still find matching records for the fields I have entered.<br>I have tried to do it through iif function but it keeps saying missing expression.<br>Please Help;<br> Grainne Evans<br><br>scan for upper(alltrim(framenum)) = upper(alltrim(m.framenum)) .and. upper(alltrim(engnum)) = upper(alltrim(m.engnum)) .and. upper(alltrim(parttype)) = upper(alltrim(m.parttype)) .and. upper(alltrim(manufact)) = upper(alltrim(m.manufact)) .and. upper(alltrim(specific)) = upper(alltrim(m.specific)) .and. upper(alltrim(model)) = upper(alltrim(m.model)) .and. upper(alltrim(year)) = upper(alltrim(m.year)) .and. upper(alltrim(engsize)) = upper(alltrim(m.engsize))<br>*scan for iif(empty(m.framenum),,upper(alltrim(framenum)) = upper(alltrim(m.framenum))) .and. iif(empty(m.framenum),,upper(alltrim(engnum)) = upper(alltrim(m.engnum))) .and. iif(empty(m.parttype),,upper(alltrim(parttype)) = upper(alltrim(m.parttype))) .and. iif(empty(m.manufact),,upper(alltrim(manufact)) = upper(alltrim(m.manufact))) .and. iif(empty(m.specific),,upper(alltrim(specific)) = upper(alltrim(m.specific))) .and. iif(empty(model),,upper(alltrim(model)) = upper(alltrim(m.model))) .and. iif(empty(m.year),,upper(alltrim(upper(year)) = upper(alltrim(m.year))) .and. iif(empty(m.engsize),,upper(alltrim(engsize)) = upper(alltrim(m.engsize)))<br> *If the record is not marked for deletion and has a current stock level<br> *of 0<br> if upper(status) = &quot;D&quot; .and. curlevel = 0<br> *The part will never be available for purchasing<br> else<br> @2,31 say &quot;Matching Part Records&quot; &&Display title<br> store .t. to m.validmat<br> clear<br> *Display details about the part<br> @6,6 say &quot;Code&quot;<br> @6,19 say partcode<br> @8,6 say &quot;Description&quot;<br> @8,19 say descrip<br> @10,6 say &quot;Manufacturer&quot;<br> @10,19 say manufact<br> @8,38 say &quot;Specific&quot;<br> @8,57 say specific<br> @10,38 say &quot;Unit Selling Price&quot;<br> @10,57 say price function &quot;$&quot;<br> store &quot;&quot; to m.response<br> define window corrpart from 20,26 to 24,56 title 'Is this the correct part?'<br> activate window corrpart<br> =clearead()<br> @1,12.5 get m.response picture '@*h Yes;No'<br> read<br> release window corrpart<br> *close data<br> store &quot;&quot; to m.howsear<br> if m.response = &quot;No&quot;<br> define window howsear from 20,16.5 to 24,60.5 title &quot;Continue searching or perform new search?&quot;<br> activate window howsear<br> =clearead()<br> @1,4.5 get m.howsear picture '@*h Continue;New Search'<br> read<br> release window howsear<br> *close data<br> if m.howsear = &quot;New Search&quot;<br> *The search for matching part records is quit<br> *and the user is returned to the new sales<br> *form to be re-prompted for a part code <br> set directory to (datapath)<br> use parts<br> locate for partcode = 0<br> store .t. to m.finished<br> endif<br> else<br> *The search for matching part records is quit and the<br> *user is returned to the new sales form. The part code<br> *of the selected record is saved and the user is<br> *re-prompted for a part code<br> store partcode to m.spartcod<br> set directory to (datapath)<br> use parts<br> locate for partcode = 0<br> store .t. to m.finished<br> endif<br> endif<br>
 
You might want to change your scan loop to use a filter instead:<br>myFilter = &quot;&quot;<br>IF .NOT. EMPTY(m.framenum)<br>&nbsp;&nbsp;myFilter = myFilter + &quot;upper(alltrim(framenum)) = upper(alltrim(m.framenum))&quot; + &quot; .AND. &quot;<br>ENDIF<br><br>IF .NOT. EMPTY(m.engnum)<br>&nbsp;&nbsp;myFilter = myFilter + &quot;upper(alltrim(engnum)) = upper(alltrim(m.m.engnum))&quot; + &quot; .AND. &quot;<br>ENDIF<br><br>...<br><br>*-- Add final .t. to close off any open ended .AND. conditions or if myFilter is empty, condition is simply &quot;.t.&quot;<br>myFilter = myFilter + &quot; .T.&quot;<br><br>SET FILT TO &myFilter.<br>SCAN<br>....<br>ENDSCAN<br>SET FILTER TO<br><br>or <br><br>SCAN FOR &myFilter.<br>...<br>
 
Grainne, I've done this very thing (using a multi-purpose screen for entering search criteria).&nbsp;&nbsp;The way I handled it was to build a search string by looking for which fields were filled in.<br><br>Here is some sample pseudo code:<br><br><FONT FACE=monospace>* -- Search button code<br>cSearch = &quot;&quot;<br>if not empty(m.framenum)<br>&nbsp;&nbsp;&nbsp;cSearch = cSearch + ;<br>&nbsp;&nbsp;&nbsp;iif(empty(cSearch), &quot; and &quot;, &quot;&quot;) + ;<br>&nbsp;&nbsp;&nbsp;&quot;framenum=&quot;+m.framenum<br>endif<br>if not empty(m.enginenum)<br>&nbsp;&nbsp;&nbsp;cSearch = cSearch + ;<br>&nbsp;&nbsp;&nbsp;iif(empty(cSearch), &quot; and &quot;, &quot;&quot;) + ;<br>&nbsp;&nbsp;&nbsp;&quot;enginenum=&quot;+m.enginenum<br>endif<FONT FACE=monospace><br><br>The above assumes the memory variables are of char type. <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
Aconsultant and Robert,<br>Why If statements and force the computer to evaluate every condition when one of the if conditions would make it invalid,&nbsp;&nbsp;A must faster loop would be <br><br>do case<br>case upper(status) = &quot;D&quot;<br>case curlevel = 0<br>case !empty(memvar) and&nbsp;&nbsp;memvar=table.field<br>case ect<br>case<br>case<br>case<br>case<br>case<br>otherwise<br>endcase<br><br> <p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br><a href= > </a><br>
 
Because, Dave, a user can enter <font color=red>multiple</font> search conditions.&nbsp;&nbsp;And sorry, <b>AConsultant</b>, I didn't see your answer already there; my mistake.&nbsp;&nbsp;I would use a <FONT FACE=monospace>select</font> rather than a <FONT FACE=monospace>set filter</font> if possible, though. <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
Guess I need to review the difference between the <font color=red> .and. </font> and the <font color=red> .or. </font> commands.&nbsp;&nbsp;The code provided tied all the if statements together with the <font color=red> .and. </font> condition.<br> <p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br><a href= > </a><br>
 
Well, that's true - and that's an assumption on my part that you would AND the search criteria.&nbsp;&nbsp;IOW, if you entered &quot;Fred&quot; in the FirstName box and &quot;Mertz&quot; in the LastName box, you would want to search for FirstName=&quot;Fred&quot; and LastName=&quot;Mertz&quot;.<br><br>But granted that is an assumption; there may well be a situation where you would want to OR the entries.&nbsp;&nbsp;But the point is: the user can enter 1-n search conditions, so you must evaluate each one to see if the user entered any criteria. <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top