Alpha Video Training
Results 1 to 5 of 5

Thread: using variables for function parameter values

  1. #1
    VAR
    Real Name
    Cheryl Lemire
    Join Date
    Jul 2003
    Location
    Pembroke Pines, FL
    Posts
    2,914

    Default using variables for function parameter values

    I have a function with the following:

    Code:
    eval("parentform:" + LinkField + ".value = " + LinkVariable)    'populate linking field with value from variable
    Where LinkField and LinkVariable above are parameters in a function:

    Code:
    FUNCTION newrecord_cont AS C (LinkField as C, LinkVariable as C, MyFirstObjectName as c)
    When calling the function, I want to use a variable for the LinkVariable parameter. Unfortunately, yet once again, I am unable to get my quotes and single quotes to work :(

    I have tried the following:

    Code:
    newrecord_cont("carr_id", '"var->vcgCarrID"', "cont_type")
    newrecord_cont("carr_id", "'+var->vcgCarrID+'", "cont_type")
    newrecord_cont("carr_id", var->vcgCarrID, "cont_type")
    None of the above are picking up the global variable value of vcgCarrID.

    The variable vcgCarrID is declared as global in the function as well as the OnPush event where I am calling the function.
    Cheryl
    #1 Designs By Pagecrazy
    http://pagecrazy.com/

  2. #2
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,763

    Default Re: using variables for function parameter values

    I haven't tried this but I think the problem is in the Eval command. Try this:

    newrecord_cont("carr_id", vcgCarrID, "cont_type")

    and use this for the eval command:

    eval("parentform:" + LinkField + ".value" ) = LinkVariable

    It might also work this way but I don't like it because there's really no need to evaluate LinkVariable:

    eval("parentform:" + LinkField + ".value = '" + LinkVariable + "'" )

    I'm not sure if you can or should include both sides of an "=" sign in one eval command but I prefer not to. To me it seems much clearer when each side is separate. And, from the tests I've run, the eval() command is very fast so using two instead of one will not be noticeable by the user.

    FYI: You can use var->vcgCarrID in the function if you really want to but in this case I just consider it unnecessary typing. The "var->" is only needed if there is a possibility of confusion about whether it is a field name or a variable. This confusion would obviously be most likely in a filter or order expression.

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

    Default Re: using variables for function parameter values

    Hi Cheryl,

    EVAL() can be used in the left side or right side of the equals sign of an expression or in a logical statement (e.g. an IF statement, where it is a logical expression equivalent to the right side of an expression. It cannot be used for the whole expression line. Examples

    IF eval("(x+2)>y")

    eval(formname+"."+varname)=eval(varname+LTRIM(STR(i)))
    If you need to evaluate 1 or more lines of code, use evaluate_template()

    The expression should look like

    eval("parentform:" + LinkField + ".value") = eval(LinkVariable)
    or

    evaluate_template("parentform:" + LinkField + ".value="+LinkVariable)
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



  4. #4
    VAR
    Real Name
    Cheryl Lemire
    Join Date
    Jul 2003
    Location
    Pembroke Pines, FL
    Posts
    2,914

    Default Re: using variables for function parameter values

    Thanks, the following worked exactly as I needed it to:

    newrecord_cont("carr_id", vcgCarrID, "cont_type")

    and use this for the eval command:

    eval("parentform:" + LinkField + ".value" ) = LinkVariable
    Cheryl
    #1 Designs By Pagecrazy
    http://pagecrazy.com/

  5. #5
    VAR
    Real Name
    Cheryl Lemire
    Join Date
    Jul 2003
    Location
    Pembroke Pines, FL
    Posts
    2,914

    Default Re: using variables for function parameter values

    Ira,

    Thanks for explaining to me why my eval was not working as I thought it would. Another learning experience as I grow with Alpha expressions :)
    Cheryl
    #1 Designs By Pagecrazy
    http://pagecrazy.com/

Similar Threads

  1. Trapping a NUL Parameter in a Function
    By KeithW in forum Alpha Five Version 7
    Replies: 3
    Last Post: 08-02-2006, 12:08 PM
  2. Setting variables ti field values external table
    By Carl Scott in forum Alpha Five Version 5
    Replies: 5
    Last Post: 12-22-2004, 02:19 AM
  3. Function Parameter calling bug?
    By csda1 in forum Alpha Five Version 5
    Replies: 0
    Last Post: 07-29-2004, 09:48 AM
  4. Report values into Variables
    By Shahin Cassim in forum Alpha Five Version 5
    Replies: 1
    Last Post: 11-02-2003, 02:41 AM
  5. get field values into variables
    By Camille Venners in forum Alpha Five Version 5
    Replies: 5
    Last Post: 04-29-2003, 09:34 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
  •