简体   繁体   中英

how to count with condition in VFP?

I am trying to count with condition in VFP.I am not trying to select anything, so I don't think I could use count here(correct me if i am wrong).

I used reccount() to count number of rows in my table, but I need to add a condition with reccount(), for example, I want to count rows with condition itemid=counter1, where itemid has repeated numbers in it, but counter1 is a counter I set up initially. So I want to count how many itemid=1 there are, and so on. Would my statement be similar to

RECCOUNT() where itemid=counter1

In manual of VFP, it seems like reccount cannot go with any conditions. I couldn't find any other ways to count with condition without the select command. Could anyone give some suggestions?

Use the " Count " keyword and the " For " clause... You can reference field(s) in the cursor in the For condition. Like this:

Select MyCursor
Count to m.count For FieldValue = 1 and Blah = .t.

Note this will move the record point in the cursor to the end, so you will need to store the Recno() and use Locate to restore it to the location it was at, if needed.

You can also use a Select statement and determine the count by referencing the special value _Tally that VFP uses after certain data row functions. Like this:

Select * from MyCursor Where FieldValue = 1 and Blah = .t. Into Array laCount

lnCount = _Tally

The cool thing about this approach is that it does not move the record pointer in the cursor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM