Alpha Video Training
Results 1 to 9 of 9

Thread: using var in table.external_record_content_get

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

    Default using var in table.external_record_content_get

    Does anyone know if you can include a variable in the table.external_record_content_get expression area?

    Example (which does not work). Getting "myvar" to appear inline next to the valid field name ("name"):

    myvar="123"
    lst = table.external_record_content_get("[PathAlias.ADB_Path]\users","name" + myvar)

    ?lst
    steve123
    mike123
    fred123
    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
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: using var in table.external_record_content_get

    lst = strtran(table.external_record_content_get("[PathAlias.ADB_Path]\users","alltrim(name)"),crlf(),myvar+crlf())+myvar

    tested, looks ok.

    Code:
    myvar = "123"
    
    ? table.external_record_content_get("atest","alltrim(svc)")
    = new
    none
    mill
    
    ? strtran(table.external_record_content_get("atest","alltrim(svc)"),crlf(),myvar+crlf())+myvar
    = new123
    none123
    mill123
    Last edited by Stan Mathews; 03-12-2010 at 04:11 PM.
    There can be only one.

  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 var in table.external_record_content_get

    Hi Steve,

    Quote Originally Posted by Steve Wood View Post
    Does anyone know if you can include a variable in the table.external_record_content_get expression area?

    Example (which does not work). Getting "myvar" to appear inline next to the valid field name ("name"):

    myvar="123"
    lst = table.external_record_content_get("[PathAlias.ADB_Path]\users","name" + myvar)

    ?lst
    steve123
    mike123
    fred123
    myvar="123"
    lst = table.external_record_content_get("[PathAlias.ADB_Path]\users","name+\"" + myvar+"\"")

    The above always will work. Depending upon scope of myvar, the following may also work

    myvar="123"
    lst = table.external_record_content_get("[PathAlias.ADB_Path]\users","name+ var->myvar")
    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
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,841

    Default Re: using var in table.external_record_content_get

    Here is what I came up with based on your help:

    Code:
    lst2 = ""
    for each foo1 in a_list
    	dta = "ulink + eval(foo1)"
    	vid = word(foo1,1,"|")
    	vemailto = word(foo1,2,"|")
    	lst2 = lst2 + table.external_record_content_get("[PathAlias.ADB_Path]\web_users","\"a|" + vid + "\"+'|'+ulink+'|'+ ""\""+ vemailto + "\"" ,"","agencyid="+quote(word(foo1,1,"|")))
    	lst2 = lst2 + crlf()
    next
    lst = lst + lst2
    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)

  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: using var in table.external_record_content_get

    Steve,
    I was doing very similar yesterday. We were probably working on them at the same time. :) Aren't they loads of fun. After a while the quotes and escapes all start to blur.

    Here are a couple of other ideas based on Stan's general idea of processing after the initial external_record_content_get.

    This one simplifies the content expression placing the variables within '{}' and then uses the evaluate_string() to replace the variables.
    Code:
    lst2 = ""
    for each foo1 in a_list
        dta = "ulink + eval(foo1)"
        vid = word(foo1,1,"|")
        vemailto = word(foo1,2,"|")
        lst2 = lst2 + table.external_record_content_get("[PathAlias.ADB_Path]\web_users","\"a|{vid}|\"+ulink+\"|{vemailto}\"" ,"","agencyid="+quote(vid))
        lst2 = lst2 + crlf()
        evaluate_string(lst2,local_variables())
    next
    lst = lst + lst2
    This one returns only the ulink and then adds the other bits with the *for_each function
    Code:
    lst2 = ""
    for each foo1 in a_list
        dta = "ulink + eval(foo1)"
        vid = word(foo1,1,"|")
        vemailto = word(foo1,2,"|")
        lst2 = lst2 + table.external_record_content_get("[PathAlias.ADB_Path]\web_users","ulink","","agencyid="+quote(vId))
        lst2 = lst2 + crlf()
        lst2 = *for_each(ln,"a|"+vid+"|"+ln+"|"+vemailto,lst2)
    next
    lst = lst + lst2
    I don't know if they are any better in any way. I haven't tested with you know who's whiz bang timer yet. ;) But if you start to run out of escape and quote characters it may make things a bit easier to work with.
    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
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,841

    Default Re: using var in table.external_record_content_get

    Yes, expressions are loads of fun! I think sometimes I go off on the deep end and create complex expressions with code indirection to see how far I can go. Then I have no idea what the code means later. Here is one that I've been glaring at for awhile:

    basefilter1 = eval("word(foo,1,\"|\")+\"->\"+word(foo,4,\"|\")+\"=\"+quote(eval(\"tbl.\"+word(foo,4,\"|\")))")

    Note - Ira's got a couple of classes on beginning and advanced xbasic, and regular expressions if anyone is interested in the subject of these particular posts. See IADN's webinar page.
    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)

  7. #7
    "Certified" Alphaholic
    Real Name
    Peter Wayne
    Join Date
    Apr 2000
    Posts
    1,728

    Default Re: using var in table.external_record_content_get

    Steve,
    You may not be aware that there is a <tbl>.record_content_get() function that is faster than table.external_record_content_get() if you're going to place it in a loop. table.external_record_content_get() opens and closes the table and its indexes for each call, which is the slowest part, usually, of table access.

    So to rewrite your code:
    Code:
    lst2 = ""
    webUsers=table.open("PathAlias.ADB_path]\web_users",file_ro_shared)
    for each foo1 in a_list
    	dta = "ulink + eval(foo1)"
    	vid = word(foo1,1,"|")
    	vemailto = word(foo1,2,"|")
    	lst2 = lst2 + \
    webUsers.record_content_get("\"a|" + vid + "\"+'|'+ulink+'|'+ ""\""+ vemailto + "\"" ,"","agencyid="+quote(word(foo1,1,"|")))
    	lst2 = lst2 + crlf()
    next
    webUsers.close()
    lst = lst + lst2
    Obviously it doesn't matter if there are only a dozen entries in the table, but if you're repetitively processing hundreds or thousands of records, it is a noticeable speed improvement. Also, depending on timing issues, doing table.external_record_content_get() thousands of times on a table can lead A5 to choke up on occasion -- probably some instances are not fully closed before the next iteration of the loop.

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

    Default Re: using var in table.external_record_content_get

    Quote Originally Posted by Steve Wood View Post
    Yes, expressions are loads of fun! I think sometimes I go off on the deep end and create complex expressions with code indirection to see how far I can go.
    Believe me, you have no idea how complicated it can get in the search for ultimate speed of an equation - nested *for_each(), eval()'s etc. :)

    Quote Originally Posted by Steve Wood View Post
    Then I have no idea what the code means later.
    Tons of comment lines showing result expression and explaining what you are doing. These are for yourself (or clients). Very often, I will show step-by-step calculations in comments, then actually use a combined expression for actual execution. To test, I can uncomment the strp-by-step version and see what is happening.

    Your first loop equation, has a couple of issues I'll bring up. You keep jumping between using single quotes, "escaped" double-quotes and the quote() function. I tend to stick with one method, rather than changing back and forth a lot. Also, be aware that in some cases you may run into, the single quote will not work within some passed expressions. This is not a bug, but a consequence of passing expressions as text strings.

    So,
    "agencyid="+quote(word(foo1,1,"|"))
    could have been written (I've added spaces around single quotes so you could see them for display here though) as either
    "agencyid=\""+word(foo1,1,"|")+"\""
    "agencyid=' "+word(foo1,1,"|")+" ' "
    "agencyid=word(\""+foo1+"\",1,\"|\")"
    The last one evaluates WORD() at filter time, rather than earlier at filter specification time. Not very useful for this case, but there are similar things that would be useful if instead of WORD(), it was a UDF function that changed results over the processing period

    The other problem is
    foo1="abc|def"
    dta = "ulink + eval(foo1)"
    vid = word(foo1,1,"|")
    vemailto = word(foo1,2,"|")
    ' This is what I think you want for the filter expr "a|abc|"+ulink+"|def"
    ' Below returns the string,
    ' (but the interactive window shows it incorrectly as it shows
    ' the contents of the string but it is one whole string despite how it appears
    ?"\"a|" + vid + "|\"+ulink+\"|"+ vemailto + "\""
    = "a|abc|"+ulink+"|def"
    ' Just to show you the difference with the interactive editor
    ?"abc"
    = "abc"
    ?"\"abc\"+def"
    = "abc"+def
    ?len("\"abc\"+def")
    = 9
    ' Same as
    ?"'abc'+def"
    = "'abc'+def"
    ?len("'abc'+def")
    = 9


    Quote Originally Posted by Steve Wood View Post
    Here is one that I've been glaring at for awhile:

    basefilter1 = eval("word(foo,1,\"|\")+\"->\"+word(foo,4,\"|\")+\"=\"+quote(eval(\"tbl.\"+word(foo,4,\"|\")))")
    There are a variety of variants that could be done, depending if foo is a constant prior to executing the filter. If foo="abc|123|456|def". do you want the filter expression to be "abc->def=tbl.def" ? In any case, the above is overly complex for this situation. It could just be
    foo="abc|123|456|def"
    ?word(foo,1,"|")+"->"+word(foo,4,"|")+"=tbl."+word(foo,4,"|")
    = "abc->def=tbl.def"
    But what I think you want is a filter expression like
    abc->def= string_constant
    which would be more like
    word(foo,1,"|")+"->"+word(foo,4,"|")+"=\""+eval("tbl."+word(foo,4,"|"))+"\""
    Last edited by csda1; 03-14-2010 at 01:37 PM.
    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



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

    Default Re: using var in table.external_record_content_get

    Thanks again. Usually when things start to look complex, it means it is no longer effecient. The whole reason I am using nexted FOR loops is my frustration with Sets. I wanted to get a nice clean simple output of every "ID" field in the entire tree/heirarchy (simplified example), either starting at the top most table, or somewhere in the middle. Someting like this, where the first col is the level, the second is the ID field:

    1|A100
    1|A101
    2|A201
    2|A300
    3|A112
    4|A554
    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. Table.external_record_content_get()
    By MikeC in forum Archived Wishlist
    Replies: 0
    Last Post: 02-10-2010, 10:55 AM
  2. table.external_record_content_get slow!
    By perry9999 in forum Alpha Five Version 8
    Replies: 1
    Last Post: 10-17-2008, 12:06 PM
  3. TABLE.EXTERNAL_RECORD_CONTENT_GET() problem
    By brett s in forum Alpha Five Version 7
    Replies: 3
    Last Post: 11-25-2006, 09:25 PM
  4. table.external_record_content_get truncated
    By Peter.Greulich in forum Alpha Five Version 7
    Replies: 3
    Last Post: 08-15-2006, 07:58 PM
  5. table.external_record_content_get
    By Blake in forum Alpha Five Version 5
    Replies: 5
    Last Post: 08-18-2003, 06:15 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
  •