April 28, 2024, 04:29:29 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Day of week puzzle and work around

Started by Andy, July 26, 2013, 01:15:47 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

This is a puzzle, although I have a work around for it (attached).

The code works fine in EB, but in IWB it doesn't.

Line causing the problem was:
N = 365 * Y + D + 31 * M + 2 - (M >= 3) * INT(.4 * M + 2.3) + INT(Y2 / 4) - INT(.75 + INT(Y2 / 100) * .75)

The actual problem was the "INT(.4 * M + 2.3)" - it should have a value say "5" and if you calculate it on its own you do get a value.

But added into the above "N = ..........." it does not?

I stored the value "c" to a string, then got the value of the string and stored it to another variable "p" and then put "p" into the calculation:

c = INT(.4 * M + 2.3)
c$ = STR$(c)
p = VAL(c$)

N = 365 * Y + D + 31 * M + 2 - (M >= 3) * p + INT(Y2 / 4) - INT(.75 + INT(Y2 / 100) * .75)

Now it works, but why? 
Andy.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

 ??? ??? ??? ??? ???
First, you don't need the C$ or p variables
just substituting c for INT(.4 * M + 2.3) will work

the puzzle is why does it equate to the proper value when you set it equal to c
yet when you insert it directly in the equation it always equates to zero

if you insert it directly in the equation but leave the INT off it does not evaluate to zero but is still off just a little.

Maybe LarryS can find time to look into it.

I don't have a clue other than that imbedded INT isn't doing what it should be doing. ??? ??? ???
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

Thanks for looking at it, it's not a major problem but it could be in some other instance.

yes, it's a puzzle.

Thanks, as always,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Bill-Bo

July 26, 2013, 02:19:14 PM #3 Last Edit: July 26, 2013, 02:21:04 PM by Bill-Bo
I have attached an eba file with a formula that be can be
use in most any basic. I've used the formula for years.

Bill

P.S. Any questions, let me know.