What am I doing wrong? 
Author Message
 What am I doing wrong?

Clarion 5.5B2  Legacy templates

I needed to work out the first day of a previous 28 day 'month' this could looks
good to me, but gives the wrong answer,  not even on a 28 day boundary point!

    GLO:LastMonth = CON:BaseDate + ((TODAY() - CON:BaseDate) / 28 - 1) * 28

This code works fine,
    Month# = ((TODAY() - CON:BaseDate) / 28 - 1)
    GLO:LastMonth = CON:BaseDate + 28 * MONTH#

It looks like the same code to me, what can I not see starring me in the face?
Somebody tell me please!

Regards Mike Renals



Mon, 25 Nov 2002 03:00:00 GMT  
 What am I doing wrong?


Quote:
>    GLO:LastMonth = CON:BaseDate + ((TODAY() - CON:BaseDate) / 28 - 1) * 28

>This code works fine,
>    Month# = ((TODAY() - CON:BaseDate) / 28 - 1)
>    GLO:LastMonth = CON:BaseDate + 28 * MONTH#

Con:BaseDate plus month# multiplied by 28 isn't quite the same as
Con:BaseDate plus 28 multiplied by month#, is it?

Also, in the first example, your month calc inside the parentheses
resolves to an intermediate floating point value whereas in your
second example you are resolving it to an integer.  This will also
allow for the possibility of dissimilar results.

Regards,
Brett C. Cammack



Mon, 25 Nov 2002 03:00:00 GMT  
 What am I doing wrong?
Thanks for the comments, but I disagree,


Quote:


>>    GLO:LastMonth = CON:BaseDate + ((TODAY() - CON:BaseDate) / 28 - 1) * 28

>>This code works fine,
>>    Month# = ((TODAY() - CON:BaseDate) / 28 - 1)
>>    GLO:LastMonth = CON:BaseDate + 28 * MONTH#

>Con:BaseDate plus month# multiplied by 28 isn't quite the same as
>Con:BaseDate plus 28 multiplied by month#, is it?

Yes it is, the order is irrelevant, maths operators are done in a strict
hierarchy, (power and %, then * and / and finally + and - ).

Quote:

>Also, in the first example, your month calc inside the parentheses
>resolves to an intermediate floating point value whereas in your
>second example you are resolving it to an integer.  This will also
>allow for the possibility of dissimilar results.

In my desperation I did try
    GLO:LastMonth = CON:BaseDate + (INT((TODAY() - CON:BaseDate) / 28) - 1) * 28
and it made no difference.
Quote:

>Regards,
>Brett C. Cammack



Mon, 25 Nov 2002 03:00:00 GMT  
 What am I doing wrong?
Mike,

the outcome of ((TODAY() - CON:BaseDate) / 28 - 1) will be a real.
Assigning it to Month# will truncate this to a long
Your difference will be:
( ((TODAY() - CON:BaseDate) / 28 - 1) - Month# ) * 28
(the fractional part times 28)

--
Best regards,
Maarten
C5EEb - ABC & C5.5b2
Certainly Clarion Developer



Tue, 26 Nov 2002 03:00:00 GMT  
 What am I doing wrong?


Quote:
>Thanks for the comments, but I disagree,
>Yes it is, the order is irrelevant, maths operators are done in a strict
>hierarchy, (power and %, then * and / and finally + and - ).
>In my desperation I did try
>    GLO:LastMonth = CON:BaseDate + (INT((TODAY() - CON:BaseDate) / 28) - 1) * 28
>and it made no difference.

Humor me...  Try:  
GLO:LastMonth = CON:BaseDate + 28 * (INT((TODAY() - CON:BaseDate) /
28) - 1)

Regards,
Brett C. Cammack



Tue, 26 Nov 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. What am I doing wrong!

2. What am I doing wrong?

3. Stupid newb question: What am I doing wrong?

4. What am I doing Wrong

5. what am i doing wrong

6. Help - What am I doing wrong

7. Saving a Variable to a field in a record- what am i doing wrong

8. What am I doing wrong?

9. What am I doing wrong?

10. #CONTROL What am I doing wrong

11. What am i doing wrong.

12. Clarion 5.5 What am I doing wrong????

 

 
Powered by phpBB® Forum Software