Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Anybody ca help mecall a function to evaluate cell in g
Message
From
30/06/1999 04:19:54
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
29/06/1999 16:11:18
Dovi Gilberd
Dovtware Consulting Inc
Miami, Florida, United States
General information
Forum:
Visual FoxPro
Category:
Visual ProMatrix
Miscellaneous
Thread ID:
00232180
Message ID:
00235727
Views:
24
>hi dragan how are you..im still with this function...can you please revise it for me to see what is it doig wrong..
>
>remember my rate table looks like this
>code country rate1 rate2 rate3
>011575 peru .23 .25 .28
>
>if john doe has rate2
>the call to 01157588888 to peru should be chaged at .25
>
>this is the code im using but its nowt shwing me .25 ..in fatc it showsme 0

Let's see. I'll just insert some comments so you can know what's going on

>FUNCTION GetRate
> LOCAL lcInAlias, lcSeekValue, lcCheckDigit, lcAssertSetting, llFoundPrefix, lnResult
> lcInAlias = ALIAS() && save the currently selected work area
> lcAssertSetting = SET('ASSERTS') && and the SET ASSERTS mode
> lcSeekValue = NULL &&default seek value to NULL
> lnResult = NULL &&default result to NULL
> llFoundPrefix = .F. &&And by default the seek failed
> SET ASSERTS ON && enable asserts
> IF ! USED('long_distance')
> * if the lookup table isn't in use already in this datasession, open it
> USE long_distance IN 0 SHARED && make sure the table is in use
> ENDIF
> SELECT long_distance && Select the lookup table before trying to find in it
> SET ORDER TO resellerid &&is correct && in the right sort order
> *
> * I use a local variable so that the LEFT() function is only called once,
> * and the code becomes a tad clearer in the DO CASE
> *
> lcCheckDigit = LEFT(view1.dialednr,1)
> * Check how many characters to use for lookup based on first character
> DO CASE
> CASE lcCheckDigit = '1'
> lcSeekValue = LEFT(view1.dialednr,4)
> CASE lcCheckDigit = '0'
> lcSeekValue = LEFT(view1.dialednr,6)
> CASE lcCheckDigit = '#'
> lcSeekValue = LEFT(view1.dialednr,3)
> CASE LEFT(view1.dialednr,3) == "411"
> * 411 calls cost $0.75 each
> lnResult = .75
> CASE LEFT(view1.dialednr,3) == "911"
> * 911 calls cost $0.00 each
> lnResult = 0.00

This is a good one from Ed - if there are less than seven digits (hyphens being filtered out), the call is assumed to be incomplete and shouldn't be charged.

> CASE LEN(ALLTRIM(CHRTRAN(view1.dialednr, '-',''))) < 7
> lnResult = 0
>
> OTHERWISE
> * Oops - the dialednr isn't in the form we expected - use an ASSERT
> * to let us know an error occurred while developing, to let us go
> * into the debugger when the error occurs. ASSERT gives us a message
> * telling us what we think went wrong as a part of the statement

Now you shouldn't have commented this ASSERT, because it is here to tell you (in development mode only) when your DialedNr has a combination of starting digits that your routine doesn't cover yet. You better uncomment it while testing, and add more CASEs up there as necessary.

> *ASSERT .F. MESSAGE 'Lead dialednr character "' + lcCheckDigit + '" not supported!'
> lnResult = 0
> ENDCASE
> IF ! ISNULL(lcSeekValue)
> * the dialednr started with a valid character, so try to find the prefix
> * we grabbed from our rate table
> llFoundPrefix = SEEK(lcSeekValue)
> ENDIF
> IF llFoundPrefix
> * found it - save the rate we found!

Now here's where the old Eval should come into play. You don't have a .rate field in long_distance, you have a rate1, rate2, rate3. Now we should assume that you have the field view1.code which holds a 2 for John Doe's call. So, we have to make it long_distance.rate2 for this case.

> lnResult = long_distance.rate

So, we'll use the same old eval() just like before, because we're constructing an expression which will hold the name of the desired field in long_distance.

lnResult=eval("long_distance.rate"+AllTrim(str(view1.code)))
> ELSE
> * oops - not in our lookup table - use ASSERT to let me know
> * what went wrong

Uncomment this Assert - it will pop up with a message when something goes wrong, and if it does, you may suspend and look in the debugger what are the values in your variables, and try to guess why did it come to this ELSE line at all. You may actually leave it in your source - Assert doesn't work in an .exe, it's ignored.

> *ASSERT ! ISNULL(lcSeekValue) MESSAGE 'Cound not find number prefix "' + lcSeekValue +'" in long_distance table'
> lnResult=0
> ENDIF
> *Restore the initially-selected work area and the ASSERT setting
> IF ! EMPTY(lcInAlias)
> SELECT (lcInAlias)
> ELSE
> SELECT 0
> ENDIF
> SET ASSERTS &lcAssertSetting
> RETURN lnResult


Just Set Asserts ON and run your code (with the few minor corrections I've made) with the debugger. It should work now - unless your view1.code is a character field, in that case the Eval() line looks like this:

lnResult=eval("long_distance.rate"+AllTrim(view1.code))

This way or other, we must have a string which says "long_distance.rate2" and EVAL() it to get the value of it. Actually, we could even do a macro here:

lCodeExt=view1.code
lnResult=long_distance.rate&lCodeExt

...and it would work the same, it's just that the Eval is somewhat quicker and easier to debug - you can copy the whole Eval() expression in the Watch window of the debugger and see what it does. It should work with macro expansion or Eval, no matter which one you pick.

And next time, please, start your work on time, and ask your questions only once or twice - the people on the UT really help each other, but nobody really wants to do someone else's homework. We all probably made an exception because you were obviously desperate - I just wandered why nobody told you it's not nice to post the same question ten times, or to send a copy of the same question to a dozen people. Meanwhile, RTFM (see the Acronyms page on UT), please.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform