Need function

Need function

Post by Terr » Sun, 21 Aug 2005 02:42:35


Hello NG,



following Scenario:



An Employee earns from 01/01/2005 to 02/13/2005 $ 13.00 an
Hour.

from 02/14/2005 to 03/31/2005
$ 12.00 an Hour.

from 01.04.2005 to 05/31/2005
$ 14.00 an Hour.

from 01.07.2005 to 08/31/2005
$ 16.00 an Hour.

etc.



What's the best way to write a function that would tell me how much he
earned on a certain date? For example on the 15th of April 2005.



Thanks for your Ideas!

Terry
 
 
 

Need function

Post by Paul Peder » Sun, 21 Aug 2005 04:20:00

DO CASE

But your specs are inconsistent. On 2/14/05 for instance, he can earn $12,
$14, or $16. It looks like you might be mixing MDY with DMY.

 
 
 

Need function

Post by Terr » Sun, 21 Aug 2005 05:21:08

Paul,

What I really wanted was a UDF to return the wages for a certain date.
The specs are inconsistent because I translated my original request from
German into English, sorry I forgot a couple of dates.

Terry


"Paul Pedersen" < XXXX@XXXXX.COM > schrieb im Newsbeitrag
 
 
 

Need function

Post by Fernando D » Sun, 21 Aug 2005 05:29:44

Hi Terry:

I think that the best choice is to use SQL.

Something like this:
SELECT Earning FROM tEarnings WHERE WorkingDay = (DesiredDate)

If you don't have day-by-day, and have a range of dates (from 01/01/2005 to
02/13/2005 ), then the SQL can be:
SELECT Earning FROM tEarnings WHERE (DesiredDate) BETWEEN WorkingDay_From
AND WorkingDay_To


Regards,

Fernando D. Bozzo
VFP6/SP5
Madrid/Spain

"Terry" < XXXX@XXXXX.COM > escribien el mensaje
>> Hello NG, >> >> >> >> following Scenario: >> >> >> >> An Employee earns from 01/01/2005 to 02/13/2005 $ 13.00 an >> Hour. >> >> from 02/14/2005 to
03/31/2005 >> $ 12.00 an Hour. >> >> from 01.04.2005 to
05/31/2005 >> $ 14.00 an Hour. >> >> from 01.07.2005 to
08/31/2005 >> $ 16.00 an Hour. >> >> etc. >> >> >> >> What's the best way to write a function that would tell me how much he >> earned on a certain date? For example on the 15th of April 2005. >> >> >> >> Thanks for your Ideas! >> >> Terry >> >> >> >>
 
 
 

Need function

Post by Paul Peder » Sun, 21 Aug 2005 05:38:33

Something like below is pretty readable. I wouldn't necessarily recommend
this, because the hard-coded dates make it inflexible, but it gives you an
idea how to proceed.

FUNCTION WageRateFromDate
LPARAMETERS tDate
DO CASE
CASE BETWEEN(m.tDate, {^2005/1/1}, {^2005/2/13})
RETURN $13
CASE BETWEEN(m.tDate, {^2005/2/14}, {^2005/3/31})
RETURN $12

<etc>

OTHERWISE
RETURN $0
ENDCASE
 
 
 

Need function

Post by Terr » Sun, 21 Aug 2005 06:27:22

The dates are no problem because they come from a Table anyway.
The wages are also in the Table.
I would change your function to something like the following:

FUNCTION SalaryFromDate
LPARAMTERS tdDate
LOCAL lnSalary
SELECT Wages
LOCATE FOR BETWEEN(tdDate, Wages.StartDate, Wages.EndDate)
IF FOUND()
lnSalary = Wages.Salary
ELSE
lnSalary = 0
ENDIF
RETURN lnSalary

Terry


"Paul Pedersen" < XXXX@XXXXX.COM > schrieb im Newsbeitrag
 
 
 

Need function

Post by Terr » Sun, 21 Aug 2005 17:36:28

Hi Fernando,

I didn't know you could use BETWEEN like that in a SQL-Select statement.
I've only used BETWEEN(eTestValue, eLowValue, eHighValue) before.

Thanks for your Answer
Terry

"Fernando D. Bozzo" < XXXX@XXXXX.COM > schrieb im Newsbeitrag
 
 
 

Need function

Post by Cindy Wine » Mon, 22 Aug 2005 01:31:55

Hi Terry,

"Between A And B" is an ANSI SQL construct. Fox's SQL engine supports most
of the ANSI SQL in addition to being able to use Xbase functions such as
Between(Value, A, B) .

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
XXXX@XXXXX.COM www.cindywinegarden.com
Blog: http://www.yqcomputer.com/