Boy, are you desperate...
OK, here's what you say:
> i know that John doe has rate 2, and he made a call to 01157587654..
> then that call with rate 2 to colombia should be billed at .24
>
> Now first i neeD to compare the first digits of the call against the rate table to see which country was called
> then i need to compare long_distance.code (rate asigned) the correct column of rates table( meaning if john doe
> had rate 3, make sure that it uses the fith column of rates table..
> now that i know the rate and the country i could knwo the rate
>
>
> im triying with this function to doit but its not working properly..
> CAN YOU PLEASE HELP ME OUT.TO CORRECT THE FUNCTION SO IT WORKS PROPERLY..
I'm assuming the code parameter is "1" for rate1, "2" for rate2 etc. You should be calling this function with
rate("01157587654", "3", 32.4) (assuming John Doe spent 32.4 minutes talking to Colombia). You'd probably have to call it with your real fields, like rate(view1.dialednr, long_distance.code, view1.minutes).
> function rate()
* not sure you can put the same parameter twice. Never tried that and wouldn't know what happens
> lparameter dialednr,code,result && ,result,n
> select rates
> set order to code
> if dialednr starts with 0 then take left 6 of dialednr compared with rates.code
if dialednr="0"
if seek left(dialednr,6)
* now watch this: since code parameter contains a "3", you'll get eval("rate3")
return eval("rate"+code)*result
else
return 0
endif
else
> if dialednr starts with 1 then take left 4 of dialednr compared with rates.code
if seek left(dialednr,4)
return eval("rate"+code)*result
else
return 0
endif
endif
Now you got me confused with this part: if your inner For loop fails to match a field, you return the number of fields plus 1, which will, of course, be wrong.
> rate=n
> return rate
> endfunc
> return rate
>
You will also have to handle the cases where the country code can't be matched. I'm returning zeros in this case, but you could actually return .null. or something else, so you'll know that it failed in those cases, and be able to do some reporting about it.