Alpha Video Training
Results 1 to 4 of 4

Thread: Expression Evaluation

  1. #1
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,842

    Default Expression Evaluation

    I know that when the below code is executed, lst will contain "my name is steve".

    dim var2 as c = "steve"
    lst = <<%txt%
    my name is {var2}
    %txt%
    lst = evaluate_string(lst)


    What I want to do is this, which would yield the same results as above when executed (pseudo code):

    dim var1 as c = "Y"
    dim var2 as c = "steve"
    dim var3 as c = "john"
    lst = <<%txt%
    if var1 = "Y"
    my name is {var2}
    else
    my name is {var3}
    end if
    %txt%

    I've done this before using a combination of evaluate_string(), evaluate_template() or eval(), but cannot remember or find the correct combo.
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  2. #2
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,615

    Default Re: Expression Evaluation

    Here's one way:

    Code:
    dim var1 as c = "Y"
    dim var2 as c = "steve"
    dim var3 as c = "john"
    lst = <<%txt%
    if var1 = "Y"
    	output = "my name is " + [varC->var2]
    else
    	output = "my name is " + [varC->var3]
    end if
    %txt%
    expr = evaluate_template(replace_parameters(lst, local_variables()))
    msgbox("", output)
    -Steve


  3. #3
    Member
    Real Name
    Jim Dusoe
    Join Date
    Aug 2008
    Location
    Maine
    Posts
    48

    Default Re: Expression Evaluation

    Steve - not sure if you are explicitly looking to use evaluate_template, but one of the simplest way to do what you want is:

    dim var1 as c = "Y"
    dim var2 as c = "steve"
    dim var3 as c = "john"
    lst = iif(var1 = "Y",var2,var3)
    ? lst
    = "steve"

    Let me know if I am missing something...
    Jim Dusoe
    Net Data Design Innovations
    Alpha Software Senior System Architect

  4. #4
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,842

    Default Re: Expression Evaluation

    Jim, I simplified my example and have many lines of text in between each IF, with embedded {var}'s . I see from Steve and Al's PM that you turn each line in to an expression (rather than plain text as I had it), then evaluate_string() will replace the vars, and evaluate_template() will process all lines as expressions.
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

Similar Threads

  1. Can you confirm expression evaluation error?
    By csda1 in forum Alpha Five Version 10 - Desktop Applications
    Replies: 6
    Last Post: 10-06-2009, 10:19 AM
  2. Expression Evaluation
    By G Gabriel in forum Alpha Five Version 8
    Replies: 5
    Last Post: 04-04-2008, 10:42 AM
  3. Evaluation
    By Frank Russ in forum Alpha Five Version 5
    Replies: 1
    Last Post: 12-26-2003, 11:34 AM
  4. Evaluation error
    By John Blum in forum Alpha Four Versions 7 and 8
    Replies: 1
    Last Post: 12-01-2003, 04:40 AM

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
  •