Home > Archive > Clipper > January 2006 > Functions and return values - simple question for a novice clipper programmer
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Functions and return values - simple question for a novice clipper programmer
|
|
|
| Hi Guys...
I am trying to convert some clipper code to a MySQL stored procedure
and it's going pretty well, however I have the following code and the
question would like to ask is when the return command is used does this
mean the function is exited immediately and the return value stored in
fraction or will the function continue even if it has found a IF
statement that is true.
I have converted this to a MySQL stored procedure but finding that it
will always run through all the IF statements so this migration will
probably involve me using a LEAVE command after setting the return
value.
fraction := mfrac(idate, sdate, edate, inv_period) // Calls function
and stores return value in 'fraction'
function mfrac(idate, sdate, edate, inv_period)
if empty(edate) // no end date
if !empty(inv_period)
if upper(inv_period) == "Q" // Quarterly
if mod(month(sdate) - month(idate), 3) == 0
return 3
else
return 0
endif
endif
if upper(inv_period) == "B" // Bi-annually
if mod(month(sdate) - month(idate), 6) == 0
return 6
else
return 0
endif
endif
if upper(inv_period) == "A" .or. upper(inv_period) == "Y"
// Annually
if month(sdate) == month(idate)
return 12
else
return 0
endif
endif
return 1 //* Monthly
endif
if sdate <= idate - day(idate) // normal - started before this
month
return 1
endif
if sdate > idate // no charge - doesnt start til later
return 0
endif
return (day(idate) - day(sdate) + 1) / day(idate)
// starter in this month - charge for part month.
endif
if sdate <= idate - day(idate) // started before this month but
coming off
if edate <= idate - day(idate) // came off prior to this month
- no charge
return 0
endif
if edate > idate // not coming off this month - charge as
normal
return 1
endif
return day(edate) / day(idate) // coming off this month -
charge for part
endif
if sdate > idate // not starting until after this month - no charge
return 0
endif
// whats left must be starting this month with an end date
if edate > idate
return (day(idate) - day(sdate) + 1) / day(idate)
endif
// whats left must start and finish this month
return (day(edate) - day(sdate) + 1) / day(idate)
| |
| PeterH 2006-01-10, 3:55 am |
| The code terminates and exits the function when a "return" is encountered.
The value is stored in "fraction"
PeterH
"Bhutz" <carltondickson@gmail.com> wrote in message
news:1136461927.019955.81960@g44g2000cwa.googlegroups.com...
> Hi Guys...
>
> I am trying to convert some clipper code to a MySQL stored procedure
> and it's going pretty well, however I have the following code and the
> question would like to ask is when the return command is used does this
> mean the function is exited immediately and the return value stored in
> fraction or will the function continue even if it has found a IF
> statement that is true.
>
> I have converted this to a MySQL stored procedure but finding that it
> will always run through all the IF statements so this migration will
> probably involve me using a LEAVE command after setting the return
> value.
>
> fraction := mfrac(idate, sdate, edate, inv_period) // Calls function
> and stores return value in 'fraction'
>
> function mfrac(idate, sdate, edate, inv_period)
>
> if empty(edate) // no end date
> if !empty(inv_period)
> if upper(inv_period) == "Q" // Quarterly
> if mod(month(sdate) - month(idate), 3) == 0
> return 3
> else
> return 0
> endif
> endif
> if upper(inv_period) == "B" // Bi-annually
> if mod(month(sdate) - month(idate), 6) == 0
> return 6
> else
> return 0
> endif
> endif
> if upper(inv_period) == "A" .or. upper(inv_period) == "Y"
> // Annually
> if month(sdate) == month(idate)
> return 12
> else
> return 0
> endif
> endif
> return 1 //* Monthly
> endif
> if sdate <= idate - day(idate) // normal - started before this
> month
> return 1
> endif
> if sdate > idate // no charge - doesnt start til later
> return 0
> endif
> return (day(idate) - day(sdate) + 1) / day(idate)
> // starter in this month - charge for part month.
> endif
> if sdate <= idate - day(idate) // started before this month but
> coming off
> if edate <= idate - day(idate) // came off prior to this month
> - no charge
> return 0
> endif
> if edate > idate // not coming off this month - charge as
> normal
> return 1
> endif
> return day(edate) / day(idate) // coming off this month -
> charge for part
> endif
> if sdate > idate // not starting until after this month - no charge
> return 0
> endif
> // whats left must be starting this month with an end date
> if edate > idate
> return (day(idate) - day(sdate) + 1) / day(idate)
> endif
> // whats left must start and finish this month
>
> return (day(edate) - day(sdate) + 1) / day(idate)
>
| |
|
| Thanks for confirming that one for me...feels good to know I know
EXACTLY what is happening
PeterH wrote:[color=darkred]
> The code terminates and exits the function when a "return" is encountered.
> The value is stored in "fraction"
>
> PeterH
>
> "Bhutz" <carltondickson@gmail.com> wrote in message
> news:1136461927.019955.81960@g44g2000cwa.googlegroups.com...
|
|
|
|
|