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

How to add corectlly?

Status
Not open for further replies.

PichiMedia

Programmer
Mar 18, 2007
11
RO
I am using Visual FoxPro8, and I have this little aplication that I just did. Among other functions, this aplication is suppose to SUM all the paychecks from a particular month. Well the SUM is wrong, or I might be missing something, I am hoping you guys might help me out. For example, I want to SUM all paychecks from March 2007. So I did a SUM ALL FOR month(MYDATE)=3 and year(mydate)=2007 to MYVAR. In this case MYVAR is 2133. But If I try and ADD per week, the first week of March, the second week of March, the third week of March, and the fourth week of March, the total is not 2133, it's usually less, like 2013 or something. It's like VFP doesn't add or SUM my numbers corectlly. It there any way to force VFP to SUM corectlly, not to make any FLOOR or CEILING? Thank you.
 
this assumes you have:
a paycheck issued date
an amount field

try:

calculate sum(<<amount field>>) for ;
between(<<paycheck issued date>>,date(2007,3,1),date(2007,3,31)) to nsum
? nsum
 
PichiMedia,

You say:

... VFP doesn't add or SUM my numbers corectlly

Let me assure you that it does. Many thousands of programs have used the SUM statement for many years. If it didn't work, we'd have known about it by now.

Also, your example for calculating the sum of March looks right, as far as I can see.

Which means the fault probably lies in your method of summing on a week-by-week basis. It's hard to be sure without seeing your code, but my guess is that the problem is something to do with determining the week boundaries. If you show us your code, we might be able to help.

But before you do that, you should check to see which result (the monthly total or the week-by-week total) is in fact the correct one. To do that, take a sample of the payslips and add them up manually.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Since the number of full and partial weeks is variable in each month, most likely you are having a problem with:

1) adding only full weeks in the month & ignoring partial weeks (ignores first few days of current month & last few days of current month)
2) adding only weeks that end during the month & ignoring partial weeks at end of month (adds part of previous month to total & ignores last few days of current month)
3) adding only weeks that begin during current month & ignoring partial weeks at the beginning of month (ignores first few days of current month & adds part of next month to the current month)
4) adding weeks that partially or completely occur in current month (adds part of previous month & part of next month to current month totals)

Basically, as noted in a previous post, you need to make sure you are using the correct boundries for your weeks.


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
I agree with myearwood
make your daily total or single record for the day amount to the same as day of month. Total for 1st is 1, total for 2nd is 2
If you miss out on a day, the error of sum of the weekly totals against the simple month total, will be the same as the day of month.
 
LOL. I see responses from everybody, including me, but nothing further from the original poster... and none of us really know what he/she is trying to do. My original take was a problem with SUM() and the weekly paychecks were added manually to verify the total he/she was getting with the SUM().
 
Imaginecorp,

I see responses from everybody, including me, but nothing further from the original poster..

Yes, I noticed that too. Unfortunately, that sort of thing happens quite often. It's discourteous, to say the least.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Lets not assume that all posters to this site have permanent and perfect mains power, telecoms, and ISP suppliers and let us also not forget that things happen in people's lives which lower the priority of responding to this site.
 
Cricket,

Maybe so. That would explain the occasional lapse. Unfortunately, you see the sort of discourteous behaviour I mentioned much too often to be blamed on occasional power cuts and the like.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Mike,

My guess is that the original poster discovered the error in their own logic that we all suspect and was to embarrassed to come back and admit it.

pamela
 
Thank you all for posting your help messages. I am sorry I could not log on to this forum, but it's not like I have INternet 24/7 like you guys. The mistake was made by me. Like I said in my original post i used somethign like this: SUM ALL FOR month(MYDATE)=3 and year(mydate)=2007 to MYVAR. Then I used thisform.text2.value=MYVAR to show the results.But I did more that this. For example, after the SUM command, MYVAR would usually be 213446, which is hard to read. I wanted to do something like 213,446 to make reading more bareable. And I used SUBSTR to exctract the numbers and arrange them the way I wanted to. Only I am not that smart and I mixed them up a little bit. I'm sorry to have bother you and I thank you again for your help.
 
Not a problem and you should not be that hard on yourself. Anybody makes mistakes.
 
I wanted to do something like 213,446 to make reading more bareable. And I used SUBSTR to exctract the numbers and arrange them the way I wanted to. Only I am not that smart and I mixed them up a little bit. I'm sorry to have bother you and I thank you again for your help.

Hey: Come on we were kidding. (at least I was), a tip, instead of substr() use transform()
Transform(<<paycheckfield>>,"@$ ###,###,###.##")
$ for currency
R for seperators only without the currency sign ($)
 
PichiMedia,

I'm sorry to have bother you and I thank you again for your help.

Nothwithstanding my earlier comment, I do assure you it's no bother. The important point is that you have solved the problem, and, besides, the thread will be useful for other people as well.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top