Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date
Message
 
To
27/06/1999 08:36:30
Dovi Gilberd
Dovtware Consulting Inc
Miami, Florida, United States
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Re: Date
Miscellaneous
Thread ID:
00232991
Message ID:
00234502
Views:
20
>hi tasker how are you today..im sorry to bother you..im stil dealing with the rate...im very new to fox, but im defending
> myself however i can...boks, forums,,etc....Im sorry to bother you..please help me
> regarding this..
>
> i created a function in my main program called rate()
> like this
>
> key things about my problem
> customer table's name is long_distance
> the field in customers where i set the rates is long_distance.code
> the calls made are in view1
> the field that has the calls is named dialednr
>
> my rates table name is Rates and it looks like this
>
> code country rate 1 rate 2 rate n
> 011575 Colombia .23 .24 .25
>
> i know that John doe has rate 2, and he made a call to 01157587654..
> then that all 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
> if dialednr starts with 0 then take left 6 of dialednr compared with rates.code
> if dialednr starts with 1 then take left 4 of dialednr compared with rates.code
> 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....I COULD PAY YOU FOR YOUR SERVICES...
>
>
> function rate()
> lparameter dialednr,code,result,result,n
> select rates
> set order to tag code
> seek left(view1.dialednr,6)
> for n=1 to fcount()
> if field(n)=upper(code)
> return eval(field(n))*result
> endif
> endfor
> rate=n
> return rate
> endfunc
> return rate

Hi Dovi,

The problem here is that you've introduced the table structure as part of it by creating a flat table. This has a number of drawbacks, including having to modify the table structure if the number of rates increases or decreases. The problem becomes much easier to manage with a structure like this:
code    rate_key  rate
011575      1     0.23
011575      2     0.24
011575      3     0.25
Note that the rate_key field is character. Then you'd simply have to create a compund index key (based on code + rate_key), and do a SEEK on those two fields.

Even though you're new to Fox and the book "Effective Techniques for Application Development using Visual FoxPro 6.0", by Jim Booth and Steve Sawyer, is aimed towards intermediate level programmers, you still might find it useful and instructive. One of the appendices covers data normalization.

hth,
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform