Macro substitution [examples]

Variable macro substitution

The & macro function substitutes the contents of the specified variable into the command line. To use a macro in the middle of a word, it is necessary to end the variable name with a ‘.’. Any type of memory variable can be substituted as a macro.

subscript = 10
i10i = 5
? i&subscript.i
         5

& macro substitution is also supported in the Command Window, Console Workspace and Console Tab in the App Inspector from v4.1.

Expression macro substitution

The & macro function can also substitute the result of an expression into the command line. The expression must be enclosed in round brackets.

subscript = "1"
i10i = 5
? i&(subscript + "0")i
         5
str1 = "hello"
str2 = "world"
echo "&str1 &str2"    // output "hello world"

& macro substitution is also supported in the Command Window, Console Workspace and Console Tab in the App Inspector from v4.1.

Shell command output substitution

Lianja provides tight integration with the Linux command shell. The ` … ` command sequence (backticks) can be used to run external shell commands that are piped together and to substitute the output into a Lianja character string.

echo "The default directory is `pwd`"
echo "There are `ls -l *.dbf | wc -l` tables in this directory"

https://www.lianja.com/doc/index.php/A_Lianja_Primer


In their simplest use just put { expression } anywhere you want a dynamic value to be substituted.

{customers.customerid}

Any expression can be substituted.

{sqllookup("southwind!employees","lastname","'{customers.empid}'","employeeid")}

When used in conjunction with {…} macros, Dialog Panels can display dynamic context sensitive content. This is the JavaScript code used to display a Google map for the customer currently being displayed in the form. It is called by clicking or touching on the “Customer Location” button in the footer menu:

Lianja.showDialogPanel("CUSTOMER LOCATION", 
    "lib:/showdialog_map.rsp?address={customers.address}
                +{customers.city}+{customers.country}", 500);

Just as you can use {expression} macros in the Lianja Desktop Client you can also use these in your Web and Mobile Apps. The following JavaScript examples show you how to use macros. You use this this same notation in desktop Apps.

Lianja.evaluate("calculateCustomerBalance('{cust.name}’)",
    function(result)
    {
        Lianja.getElementByID("mypage.mysection.myfield").text = result;
    },
    function(errormessage)
    {
        Lianja.showErrorMessage("Failed to calculate customer balance");
    }
);
// execution continues before the result is returned

Macros are evaluated from left to right:

Lianja.evaluate("calculateCustomerBalance('{customers.name}','{customers.id}’)",
    function(result)
    {
        Lianja.getElementByID("mypage.mysection.myfield").text = result;
    },
    function(errormessage)
    {
        Lianja.showErrorMessage("Failed to calculate customer balance");
    }
);
// execution continues before the result is returned

Macros can be nested so that the inner macros are evaluated before the outer macros. This provides the ability to query information from the server and have that information substituted into another call to the server.

Lianja.evaluate("calculateCustomerBalance('{customers.name}'," + "{getCustomerID('{{customers.custid}}')}")),
    function(result)
    {
        Lianja.getElementByID("mypage.mysection.myfield").text = result;
    },
    function(errormessage)
    {
        Lianja.showErrorMessage("Failed to calculate customer balance");
    }
);
// execution continues before the result is returned

This will result in the following macro substitutions being performed in this order.

 {{customers.custid}} lets call this result3
 {customers.name} let's call this result1
 {getCustomerID("result3")} let's call this result2
 Lianja.evaluate("calculateCustomerBalance('result1', "result2")

https://www.lianja.com/doc/index.php/Understanding_Macros


 

Enable or disable & macro substitution
SET_MACROS
SET_EMACROS
set emacros off
text
The & command is used to perform
macro substitution of the contents
of memory variables.
endtext
set emacros on

https://www.lianja.com/doc/index.php/SET_EMACROS

https://www.lianja.com/doc/index.php/SET_MACROS


Perform macro substitution

subscript = 10
i10i = 5
? i&subscript.i
         5

https://www.lianja.com/doc/index.php/%26


Macros

Variable macro substitution

The & macro function substitutes the contents of the specified variable into the command line. To use a macro in the middle of a word, it is necessary to end the variable name with a ‘.’. Any type of memory variable can be substituted as a macro.

subscript = 10
i10i = 5
? i&subscript.i
         5

& macro substitution is also supported in the Command Window, Console Workspace and Console Tab in the App Inspector from v4.1.

Expression macro substitution

The & macro function can also substitute the result of an expression into the command line. The expression must be enclosed in round brackets.

subscript = "1"
i10i = 5
? i&(subscript + "0")i
         5
str1 = "hello"
str2 = "world"
echo "&str1 &str2"    // output "hello world"

& macro substitution is also supported in the Command Window, Console Workspace and Console Tab in the App Inspector from v4.1.

Shell command output substitution

Lianja provides tight integration with the Linux command shell. The ` … ` command sequence (backticks) can be used to run external shell commands that are piped together and to substitute the output into a Lianja character string.

echo "The default directory is `pwd`"
echo "There are `ls -l *.dbf | wc -l` tables in this directory"

https://www.lianja.com/doc/index.php/A_Recital_Primer


Advertisements

Macro

Q:
The problem appears to be the ‘&sql’ executing inside a try block, if this happens and then an error is generated afterwards, the crash occurs.
Changing various elements of the code causes the problem not to occur, this was the only combination where I could get it to happen reliably.

Code:
////////////////////////////////////////////////////////////////
// Event delegate for 'click' event
proc page1_section2_field2_click()

        dbName = "mydb"
        if ExecuteCommand1('open database &dbName')         
               
                private tab[]                   
                tab._name = "a"
                //This will raise an error
                if tab.name = "a"
                endif           
               
        endif   
       
endproc


function ExecuteCommand1(sql)

        try             
                &sql
                return .T.
        catch to e
                return .F.             
        endtry
       
endfunc

A:
Put the return statements outside the try/endtry block:
RETURN is also not allowed inside a TRY block or a CATCH block

Code:
function ExecuteCommand1(sql)

        try
                &sql
                // ? "Tried"
                lreturn  = .T.
        catch to e
                // ? "Caught"
                lreturn  = .F.
        endtry
                return lreturn
endfunc


 

Macro

Q:
My goal is to create a function to clear column data (‘old value’ and ‘new value’) from any array based on array name.
A:
you could pass the array name and macro substitute it where necessary.

Code:
public arr1(5,3)
arr1(1,1) = 'txtName'
arr1(1,2) = 'test'
arr1(1,3) = 'testing'
? arr1

proc myproc
    para myarray
    &myarray(1,2) = .f.
    &myarray(1,3) = .f.
    ? arr1
endproc

do myproc with "arr1"

Q:
what does the ‘&’ sign just before the (field(i)) do? (? &(field(i)))
A:
The “&” character indicates a macro substitution:
http://www.lianja.com/doc/index.php/%26



Macro

Q:

Code:
SELECT COUNT(GSID) AS CountEntry FROM bantam_stats!gamesheet WHERE gamenumber = &GameNumber AND hometeam IN ("&strTeamID")

A:
Remove the quotes:
IN (&strTeamID)


Q:

Code:
lcCursor = "Cursor2"
open database southwind
use shippers
select 0
select * from shippers into cursor (lcCursor)
insert into shippers select * from (lcCursor)

A:
Why not just use a &cursor2
lianja supports macro expressions too &(basename(cursor2))