Archive for the ‘Macro’ Category

Macro

Posted: 2017-01-19 in 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

Posted: 2017-01-19 in 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

Posted: 2017-01-19 in 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))