Hello,

Here is the scenario, I am adding up totals for counties in a certain state. The order of the counties is mixed up and counties can show up more then once with a different amount. I need to put those numbers and their county into an array.

My problem is how to go about checking to see if the county is already loaded in the array so that I can add it to that total.

Thank you,

### Re: Array incrementing

Naomi Nosonovsky

You can always use ASCAN function to check if the value is already in array. However, I think your problem can be easily solved with Select-SQL into array.

Give us a little bit more details about what do you want to achieve, please.

### Re: Array incrementing

Okay, heres a bit better of an explanation:

I have a table that has stored in it 6 fields, 3 of them store the county information (state, county, city) the other 3 store the money amount. I want to take them and compress it into a report that prints the totals for each state, county and city. But they are in random order so I need to read them into an array and total them up. I can't figure out how to do this in the sense that I need to check if the state, county, or city is already there to add the total to.
store cState to tempState
store cCounty to tempCounty
store cCity to tempCity

do while cState = tempState
tempArray(,) = tempArray(,) + nTotal1
do while cCounty = tempCounty
tempArray(,) = tempArray(,) + nTotal2
do while cCity= tempCity
tempArray(,) = tempArray + nTotal3
enddo
enddo
enddo

Something like that maybe, similiar to how I did it in my COBOL or C days. Hope this was helpful.

### Re: Array incrementing

Naomi Nosonovsky

VFP is all about data manipulation. Your problem can be solved with this SQL:

Code Snippet

select State, County, City, sum(amount1) as Total_Amount1, sum(amount2) as Total_Amount2, sum(amount3) as Total_Amount3 from yourTable group by 1,2,3 into cursor curTotals && or you can do into array arrTotals

Now you can use cursor or array in your report. (Easier with a cursor).

Also you can always have a compound index in your table