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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with "scan..for..endscan"

Status
Not open for further replies.

iimogenca

Technical User
Feb 8, 2011
1
CA
I am a new foxpro programmer. Recently I am having a problem with using "scan..for..endscan".

I am working with 2 tables, the 1st one is called criteria, which contains item_name, sumfv(the total value of the fv column in the 2nd table based on different conditions), and a condition column used to store these conditions; the 2nd table is called data, which contains the raw data, including a fv column.I need to extract data from 2nd table based on the conditions from 1st table, then add fv in the 2nd one to the sumfv column in criteria table(1st one).

part of my code is as below:
....
SELECT criteria
GO TOP
SCAN

SELECT data
CALCULATE SUM(fv) FOR AllTRIM(criteria.condition) TO sum
SELECT criteria
REPLACE sumfv WITH sum

ENDSCAN
....

However, when I run this program, it pops up an error message saying FOR should be used with a logical expression. The data type I set for criteria.condition is character..Does anyone know how to fix this problem?

I really appreciate your help!!

Thanks!
 
The problem is in this line:

Code:
CALCULATE SUM(fv) FOR AllTRIM(criteria.condition) TO sum

Just as the error message says, VFP is expecting a logical value (that is, .T. or .F.) as the operand of the FOR clause. You are giving it a character value.

You say your Condition field contains the condition. Do you mean it contains something like "A = B", that is, an entire expression that evaluates to .T. or .F.?

If so, modify the above line as follows:

Code:
CALCULATE SUM(fv) FOR [b]EVALUALTE([/b]AllTRIM(criteria.condition)[b])[/b] TO sum

Or, do you mean that Condition contains a string, and the condition is true when something else equals that string? In that case, you FOR clause would have to contain the complete condition, something like FOR A = AllTRIM(criteria.condition).

If you could clarify exactly what is in the Condition field, we can give you more guidance.

Miike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
You might also try another approach which does not involve having to run SCAN/ENDSCAN.

Something like:
Code:
* --- Get ALL Sum Values From Data ---
SELECT Data.condition,;
   SUM(Data.fv) AS Cond_Sum;
   FROM Data, Criteria;
   WHERE ALLTRIM(Criteria.Condition) == ALLTRIM(Data.Condition);
   GROUP BY Data.Condition;
   INTO CURSOR Results READWRITE

SELECT Results
INDEX ON Condition TAG Sums

* --- Replace Values In Criteria ---
SELECT Criteria
SET RELATION TO Condition INTO Results
REPLACE ALL sumfv WITH Results.Cond_Sum

Good Luck,
JRB-Bldr
 
Mike has the right question there. The question is, what is in the condition field?

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top