Alpha Video Training
Page 1 of 2 12 LastLast
Results 1 to 30 of 31

Thread: Return values from a FUNCTION

  1. #1
    Member
    Real Name
    Don Walton
    Join Date
    Mar 2001
    Posts
    123

    Default Return values from a FUNCTION

    I am using this FUNCTION: xyz as C (Vend,(PO,Err ) and i can not get the function to return any values!! I understood that in the function you could set XYZ to some character value and/or that you can change the values of PO and Err in the FUNCTION!! I just can not get this to work!! Can anyone show me the correct way to use a FUNCTION??? The FUNCTION does what it is supposed to do but will NOT return any values!!

    Don Walton
    352-243-3303

  2. #2
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,628

    Default Re: Return values from a FUNCTION

    Can you post the function?
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  3. #3
    "Certified" Alphaholic DaveM's Avatar
    Real Name
    Dave Mason
    Join Date
    Jul 2000
    Location
    Hudson, FL
    Posts
    6,026

    Default Re: Return values from a FUNCTION

    Function xyz as c etc.

    last line is: xyz = whatever is desired
    end function

    That should cause it to return the value of xyz.

    like this:

    Code:
    function discretiontaxget as N(taxable as N,countytaxrate as N,max as N)
    dim mcountytax as n
    if   countytaxrate = 1.00 .and. taxable < max then
        mcountytax = taxable * (countytaxrate/100)
    elseif  countytaxrate = 1.00 .and. taxable >= max then
        mcountytax = 50.00
    elseif countytaxrate = .50 .and. taxable < max then
        mcountytax = taxable * (countytaxrate/100)
    elseif  countytaxrate = .50 .and. taxable >= max then
        mcountytax = 25.00
    elseif countytaxrate = .75 .and. taxable < max then
        mcountytax = taxable * (countytaxrate/100)
    elseif countytaxrate = .75 .and. taxable >= max then
        mcountytax = 37.50
    elseif countytaxrate = 1.25 .and. taxable < max then
        mcountytax = taxable * (countytaxrate/100)
    elseif countytaxrate = 1.25 .and. taxable >= max then
        mcountytax = 62.50
    elseif  countytaxrate = 0 then
        mcountytax = 0.00
    end if 
    discretiontaxget = mcountytax
    end function
    Last edited by DaveM; 11-11-2014 at 11:58 PM.
    Dave Mason
    dave@aldausa.com
    Skype is dave.mason46

  4. #4
    Member
    Real Name
    Don Walton
    Join Date
    Mar 2001
    Posts
    123

    Default Re: Return values from a FUNCTION

    This is what I did almost exactly!! The difference is that I tried to change the parameters that were sent to the function - in your case - taxable as N,countytaxrate as N,max as N!! Ie, setting taxable to a value etc!! It seems that the only values that can be returned are in the name of function - discretiontaxget!! Is it always just a SINGLE value that can be returned?

  5. #5
    "Certified" Alphaholic Tim Kiebert's Avatar
    Real Name
    Tim Kiebert
    Join Date
    Jul 2004
    Location
    Geelong, Victoria, Australia
    Posts
    2,785

    Default Re: Return values from a FUNCTION

    Quote Originally Posted by DonWalton View Post
    This is what I did almost exactly!! The difference is that I tried to change the parameters that were sent to the function - in your case - taxable as N,countytaxrate as N,max as N!! Ie, setting taxable to a value etc!! It seems that the only values that can be returned are in the name of function - discretiontaxget!! Is it always just a SINGLE value that can be returned?
    Here is a pointer (pun intended) to some function help. Start on this page and then follow the 'See also' links

    Some examples
    Using with ... end with
    Code:
    dim txt as C = "aaa"
    dim num as N = 3
    dim lv as P = local_variables()
    
    msgbox("Local vars before", txt + "  " + num)
    msgbox("return from function",dosomething(lv))
    msgbox("Local vars after", txt + "  " + num)
    
    
    Function dosomething as C (lv as P)
    	dim text as C
    	dim numb as N
    	with lv
    		txt = "bbb"
    		text = txt
    		num = num * 2
    		numb = num
    	end with
    	dosomething = text + "  " + numb
    End function
    Using byref
    Code:
    dim txt as C = "aaa"
    dim num as N = 3
    
    msgbox("Local vars before", txt + "  " + num)
    msgbox("return from dosomething",dosomething(txt,num))
    msgbox("Local vars after dosomething", txt + "  " + num)
    
    
    dosomethingelse(txt,num)
    msgbox("Local vars after do something else", txt + "  " + num)
    
    
    
    Function dosomething as C(byref text as C, byref numb as N)
    		text = "bbb"
    		numb = numb * 2
    		dosomething = "something completely unrelated"
    End function
    
    Function dosomethingelse as V(byref text as C, byref numb as N)
    		text = "ccc"
    		numb = numb * 4
    End function
    Using a Pointer
    Code:
    dim result as P
    result = return_a_pointer()
    msgbox(result.Name + " lives in " + result.city)
    
    function return_a_pointer as P()
    	dim return_a_pointer as P
    	return_a_pointer.name = "Tim"
    	return_a_pointer.city = "Geelong"
    end function
    You could also return a crlf delimited string that contains a particular value on each line.
    You could take that further and put name:value pairs on each line.
    And using the flavour of the month you could return fully formed JSON
    Last edited by Tim Kiebert; 11-12-2014 at 03:08 AM.
    Tim Kiebert
    Eagle Creek Citrus
    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

  6. #6
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Re: Return values from a FUNCTION

    Don asked: Is it always just a SINGLE value that can be returned?
    Yes, that's right. But the "single" value might be a character string containing formatted data. The script that calls the function would then be responsible for parsing the string returned by the function.

    For example a function might return both a first and a last name, formatted as a single character string. Like this:

    "WALTON | DON"

    The string returned by the function could then be separated into first and last names.

  7. #7
    "Certified" Alphaholic DaveM's Avatar
    Real Name
    Dave Mason
    Join Date
    Jul 2000
    Location
    Hudson, FL
    Posts
    6,026

    Default Re: Return values from a FUNCTION

    You can return more than one value from a function, but subversely.
    for instance:
    declare a variable as global, assign it a value in the function and the use the variable anywhere. I have one function that gives a car payment and then does all the other math and those numbers are either placed in variables or placed in fields on the form directly as they are computed.
    This way I have the interest and balance as well as the payment all complete.
    Like this:

    Code:
    FUNCTION pmtonapr AS N (p as n, r as n, mos as n, type as n, daystofirst as n)
    dim global balance as n
    dim global interest as n
    if r <= 0.00 then
        pmtonapr = p/mos
    else
    dim df as n
    dim rte as n = (r/100)/12
    df = round_UP((daystofirst-30)/30,6)
    dim trm as n = 0
    dim formu as n
    'dim factor as n 
    var->factor = round_up((rte*df)*p,8) 'round_down() does not work in v7
    formu = round_up(p+var->factor,5)
    pmtonapr = round_down(pmts1(formu,r,mos),2)
       
    end if
    var->balance = pmts*mos
    var->interest = var->balance-p
    
    end function
    Last edited by DaveM; 11-12-2014 at 01:37 PM.
    Dave Mason
    dave@aldausa.com
    Skype is dave.mason46

  8. #8
    Member
    Real Name
    Don Walton
    Join Date
    Mar 2001
    Posts
    123

    Default Re: Return values from a FUNCTION

    Tim

    Thank you for the reply!! I am definitely doing something wrong - when the FUNCTION ENDs and returns to the calling script, the name of the FUNCTION is always blank, IE does not contain the RESULT of the FUNCTION!! If I had a FUNCTION defined as XYZ as C (PO as C), the FUNCTION would set XYZ to a character result and the calling script,upon return from the FUNCTION, should be able to use XYZ and set it to a variable, for instance Char=XYZ!! I have tried so many things and I just cant get anything to work!!

  9. #9
    Member
    Real Name
    Don Walton
    Join Date
    Mar 2001
    Posts
    123

    Default Re: Return values from a FUNCTION

    Thanks you!! Very helpful and I thank you!!

  10. #10
    Member
    Real Name
    Don Walton
    Join Date
    Mar 2001
    Posts
    123

    Default Re: Return values from a FUNCTION

    This help me alot and I thank you!!

  11. #11
    "Certified" Alphaholic DaveM's Avatar
    Real Name
    Dave Mason
    Join Date
    Jul 2000
    Location
    Hudson, FL
    Posts
    6,026

    Default Re: Return values from a FUNCTION

    Don,
    Is this a web app you have or a desktop app?
    Dave Mason
    dave@aldausa.com
    Skype is dave.mason46

  12. #12
    Member
    Real Name
    Don Walton
    Join Date
    Mar 2001
    Posts
    123

    Default Re: Return values from a FUNCTION

    It is a desktop application!!

  13. #13
    "Certified" Alphaholic DaveM's Avatar
    Real Name
    Dave Mason
    Join Date
    Jul 2000
    Location
    Hudson, FL
    Posts
    6,026

    Default Re: Return values from a FUNCTION

    Ok. This statement through me and is the reason for the question.

    IE does not contain the RESULT of the FUNCTION!!
    Dave Mason
    dave@aldausa.com
    Skype is dave.mason46

  14. #14
    "Certified" Alphaholic DaveM's Avatar
    Real Name
    Dave Mason
    Join Date
    Jul 2000
    Location
    Hudson, FL
    Posts
    6,026

    Default Re: Return values from a FUNCTION

    To use the function like most functions:
    from the calling script,
    dim anyvar as c
    anvar = xyz() and whatever calls are needed in zyz.
    Like the pmt function above when called is like this.
    Code:
    var->vpmt = pmtonapr(var->vfinance+var->vdocs,mon->aprate,mon->term,mon->termtype,mon->daystofirst)
    After, the variable "vpmt" has the results in it.
    Dave Mason
    dave@aldausa.com
    Skype is dave.mason46

  15. #15
    Member
    Real Name
    Don Walton
    Join Date
    Mar 2001
    Posts
    123

    Default Re: Return values from a FUNCTION

    Dave

    If the name of the FUNCTION is XYZ as C() then when the function ends & returns to the calling script, XYZ should contain the result. Right? XYZ is always blank!!??!! Yet i knpow that the FUNCTION executed correctly - i watched it run with DEBUG() and XYZ contains the correct return but when I look at it in the calling program it is BLANK

  16. #16
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Re: Return values from a FUNCTION

    Don,

    try:

    dim My_Result as C
    My_Result = XYZ()
    msgbox("Status",My_result)


    XYZ is a function name, it's not a variable.

  17. #17
    Member
    Real Name
    Don Walton
    Join Date
    Mar 2001
    Posts
    123

    Default Re: Return values from a FUNCTION

    Tom

    This is what I needed to know!! I knew I was doing something wrong and that is it - have to use the parentheses!! Will try it!!

  18. #18
    Member
    Real Name
    Don Walton
    Join Date
    Mar 2001
    Posts
    123

    Default Re: Return values from a FUNCTION

    THE ANSWER IS that the FUNCTION has to be called from the script as Char = XYZ()!! Char now contains the value returned by the function!! This is what I did not know!! THANK YOU!!

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

    Default Re: Return values from a FUNCTION

    Glad you got it.

    The answer is, a user defined function performs pretty much the same as a built in function.

    Char = XYZ()

    just as you would say

    Char = STR(12345)
    There can be only one.

  20. #20
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,699

    Default Re: Return values from a FUNCTION

    Of course the confusion arises because in the IW, some functions will return a value just by doing this:

    ?xyz()
    ="something"

    Whereas others must set a variable to get the return value - it would by good to know the difference for this...
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

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

    Default Re: Return values from a FUNCTION

    Whereas others must set a variable to get the return value
    Are you meaning one must supply a parameter?
    There can be only one.

  22. #22
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,699

    Default Re: Return values from a FUNCTION

    No, I meant that in the IW sometimes

    Vc = myfunction() will return a result for vc whereas

    ?myfunction() won't

    I still have trouble getting functions that use an XD to return a result...in either case.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

  23. #23
    "Certified" Alphaholic DaveM's Avatar
    Real Name
    Dave Mason
    Join Date
    Jul 2000
    Location
    Hudson, FL
    Posts
    6,026

    Default Re: Return values from a FUNCTION

    Let me say that any variable that has been declared and value set in a function as shared or global can be read from the appropriate place. Global = anywhere, shared = from the calling form or...
    Dave Mason
    dave@aldausa.com
    Skype is dave.mason46

  24. #24
    "Certified" Alphaholic DaveM's Avatar
    Real Name
    Dave Mason
    Join Date
    Jul 2000
    Location
    Hudson, FL
    Posts
    6,026

    Default Re: Return values from a FUNCTION


    Vc = myfunction() will return a result for vc whereas

    ?myfunction() won't

    I still have trouble getting functions that use an XD to return a result...in either case.
    it would depend on function type. Like a logical function would return .t. or .f..
    A function that declares a return value will retur what it is supposed to.
    A function may just create shared or global variables and you would need to know what the variables are.
    A function that does a job like updating a table may return nothing you can see.
    Dave Mason
    dave@aldausa.com
    Skype is dave.mason46

  25. #25
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,628

    Default Re: Return values from a FUNCTION

    Quote Originally Posted by MoGrace View Post
    No, I meant that in the IW sometimes

    Vc = myfunction() will return a result for vc whereas

    ?myfunction() won't

    I still have trouble getting functions that use an XD to return a result...in either case.
    Robin

    Can you give examples of that?
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  26. #26
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,699

    Default Re: Return values from a FUNCTION

    Hi Al,
    This zip contains my exported function and 2 small text files that should be in the same directory as the function when you import it. It is using the clipboard but will not return a value otherwise in the IW. Let me know what you think - I have others!
    Attached Files Attached Files
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

  27. #27
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,628

    Default Re: Return values from a FUNCTION

    Quote Originally Posted by MoGrace View Post
    Hi Al,
    This zip contains my exported function and 2 small text files that should be in the same directory as the function when you import it. It is using the clipboard but will not return a value otherwise in the IW. Let me know what you think - I have others!
    Getting this error message on 2 machines...

    RobinUnzip.png

    Try attaching them without zipping them. They don't look like they are too big. Or email them to me.
    Last edited by Al Buchholz; 12-24-2014 at 04:18 PM.
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  28. #28
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,699

    Default Re: Return values from a FUNCTION

    Its because I am unloading from home with IE8 - it makes the upload feature here hang. I will try again.
    Attached Files Attached Files
    Last edited by MoGrace; 12-24-2014 at 04:29 PM.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

  29. #29
    Member
    Real Name
    Allen Klimeck
    Join Date
    Apr 2000
    Location
    Colorado
    Posts
    539

    Default Re: Return values from a FUNCTION

    You are using a modeless dialog box so the dialog opens but the code continues to run and the function finishes with the dialog box open it can't return anything.

  30. #30
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,699

    Default Re: Return values from a FUNCTION

    Allen,
    So my problem would be resolved if I give up the roll up feature and go modal? Thanks, I'll try it. I want to call this function from my floating modeless toolbar (used for development only) so I guess I don't really need the modeless roll up feature.

    Merry Christmas!
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

Similar Threads

  1. Return multiple values from a lookup grid
    By rjackson@arach.net.au in forum Application Server Version 11 - Web/Browser Applications
    Replies: 0
    Last Post: 05-06-2012, 02:01 AM
  2. Limiting Tree return values
    By murraycam in forum Alpha Five Version 8
    Replies: 6
    Last Post: 12-09-2009, 06:36 AM
  3. 21 Feb 2009 : passing values to asp.net and getting return value
    By yemulss in forum Application Server Version 9 - Web/Browser Applications
    Replies: 0
    Last Post: 02-21-2009, 08:54 AM
  4. Drop Down return multiple values
    By jbeddes in forum Web Application Server v6
    Replies: 2
    Last Post: 02-09-2005, 11:21 AM
  5. Function return
    By Stan Mathews in forum Alpha Five Version 4
    Replies: 7
    Last Post: 04-24-2001, 03:18 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
  •