1. ## Function return

Have fun, find my dumb mistake!

I was playing with creating a function to perform the "four prices for one item, find the lowest" situation described in another post. I have a function that works in the interactive tab and works in the expression builder - if you hit the evaluate button. It returns the lowest number parameter in the format like 1.000000.

However, if I try to use it in a field rule or calculated field for a form, Alpha thinks the return value is character instead of numeric.

The function is posted below. If no one can spot a simple error or explain the problem, I'll zip up a amall sample displaying the problem.

Simple table:

idnum,c,4,0
name,c,10,0
aprice,n,10,2
bprice,n,10,2
cprice,n,10,2
dprice,n,10,2
lowest,n,10,2

lowest field rule, calculated type, expression ==

least(aprice,bprice,cprice,dprice)
When I try to save the table after creating this field rule, I get an error "Command: least(.....) variable type mismatch.

function:

function least as N(inputa as N,inputb as N,inputc as N,inputd as N)

least = case(inputa

2. ## RE: Function return

Stan, maybe the field rule is interpreting the field references as variable names?

Try making explicit references like this:

least(tablename->aprice,tablename->bprice,tablename->cprice,tablename->dprice)

3. ## RE: Function return

That didn't work either, thanks.

Here's the sample.

4. ## RE: Function return

Didn't have all the files in one folder. Maybe better now.

5. ## RE: Function return

Stan,

The problem is with the least function. The way you have it defined, it assumes that the smallest value is less than all other values, but in many cases, it is the same as 1 or more of the other values, in which case there is no expression in the case function that evaluates true. It then returns no value, which causes your use of it to fail.

E.g. try in the interactive editor

?least(2,1,1,3)

Regards,

Ira J. Perlow
Computer Systems Design & Associates
csda@mediaone.net

6. ## RE: Function return

I knew it would be obvious to someone else.

Thanks,

Stan

7. ## RE: Function return

I agree with Ira about having a problem with matching prices, but a quick solution to mismatch would:

val(least(inputa,inputb,inputc,inputd))

will return numeric value every time

Oran

8. ## RE: Function return

Oran,

That returns no value. In fact it returns an error. To find the least value, one could use an expression like

least=min(inputa,min(inputb,min(inputc,inputd)))

A more complex expression would be to return which of the 4 inputs was the least.

Regards,

Ira J. Perlow
Computer Systems Design & Associates
csda@mediaone.net

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•