Alpha Video Training
Results 1 to 8 of 8

Thread: Function return

  1. #1
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default 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. #2
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,311

    Default 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. #3
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default RE: Function return

    That didn't work either, thanks.

    Here's the sample.

  4. #4
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default RE: Function return

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

  5. #5
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default 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. #6
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default RE: Function return

    I knew it would be obvious to someone else.

    Thanks,

    Stan

  7. #7
    Oran Hamilton
    Guest

    Default 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. #8
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default 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

Similar Threads

  1. Return to browse
    By pstaver in forum Alpha Five Version 6
    Replies: 12
    Last Post: 12-15-2004, 08:17 AM
  2. Sloooow return to operation
    By AL@ALCO-SALES.COM in forum Alpha Five Version 6
    Replies: 5
    Last Post: 08-09-2004, 07:03 AM
  3. ok and return
    By Ian_Edwards in forum Alpha Five Version 6
    Replies: 3
    Last Post: 08-02-2004, 01:26 PM
  4. Function to return multiple answers?
    By Daniel Weiss in forum Alpha Five Version 5
    Replies: 5
    Last Post: 10-28-2002, 11:37 PM
  5. Return for OK
    By Keith Hubert in forum Alpha Five Version 5
    Replies: 2
    Last Post: 10-16-2002, 12:25 PM

Bookmarks

Posting Permissions

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