Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

ExecScriptFast() 07 Aug 2021 18:28 #19269

  • Karl-Heinz
  • Karl-Heinz's Avatar
  • Topic Author


  • Posts: 774
  • The new script compiler looks very promising !

    The only problem i´ve noticed so far is that Type() always returns "U" if "LPARAMETERS" is used in the script. There´s no such problem if "PARAMETERS" is used instead.

    That´s the output of the attached XSharpFoxProScript.viaef

    PARAMETERS a,b,c
    ? VarType (a), VarType ( b ), VarType(c)
    ? Valtype (a), Valtype ( b ), Valtype(c)
    ? Type ('a'), Type ( 'b' ), Type('c') // comment1 ...
    ? Substr ('aaaxxxaaa' , 4 , 3 ) && comment2 ...
    RETURN SubStr(a,b,c)
    
    C N N
    C N N
    C N N
    xxx
    Str
    
    LPARAMETERS a,b,c
    ? VarType (a), VarType ( b ), VarType(c)
    ? Valtype (a), Valtype ( b ), Valtype(c)
    ? Type ('a'), Type ( 'b' ), Type('c') // comment1 ...
    ? Substr ('aaaxxxaaa' , 4 , 3 ) && comment2 ...
    RETURN SubStr(a,b,c)
    
    C N N
    C N N
    U U U  <--------------- should show C N N
    xxx
    Str
    
    PARAMETERtest C N N
    LPARAMETERtest C N N

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    ExecScriptFast() 08 Aug 2021 14:32 #19281

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • Guys,

    This script uses DB commands. Simply add the sources to the previously posted viaef.
    cTest := String.Join(e"\n",<STRING>{; 
    	"#INCLUDE 'DBCmd.xh'",; 
    	"#INCLUDE 'FoxProCmd.xh'",;
    	"PRIVATE lRet" ,;
    	"lRet := true" ,;
    	"" ,;
    	"USE D:\test\small.dbf" ,;
    	"IF Used()",;
    	"?  'Selected area:' , Select()" ,;
    	"?" ,;
    	"   SET ORDER TO 1" ,;
    	"   SCAN    && FOR small->LAST < 'U'" ,;         
    	"     ? small->LAST",; 
    	"   ENDSCAN",; 
    	"   CLOSE" ,;	
    	"ELSE" ,;
    	"   lRet := false" ,;
    	"ENDIF",; 
    	"?" ,;
    	"RETURN lRet" })	    
    	    
    	?
    	? cTest
    	? 
    	        
    	? "Script result:" , ExecScriptFast ( cTest )   	          
    	?

    The script tries to do the same as this code does
    USE D:\test\small.dbf 
    	IF Used()
    		SET ORDER TO 1
    		SCAN FOR a->LAST < 'U'         
    			? a->LAST 
    		ENDSCAN
    		CLOSE    
    	ENDIF

    The Scripting problems i found:

    - Using the 'a->' alias fails.
    - the SCAN FOR condition fails.
    - The ":=" assignment must be used.

    Before you run the code make sure to adjust the currently used "D:\TEST" folder. Attached are the required
    small.dbf and small.cdx

    Note: I forgot to mention in my previous post that I´m using the 2.8c build !

    regards
    Karl-Heinz
    Attachments:

    Please Log in or Create an account to join the conversation.

    ExecScriptFast() 09 Aug 2021 08:01 #19284

    • robert
    • robert's Avatar


  • Posts: 3448
  • Karl Heinz,
    Thanks for the feedback.
    I'll discuss it with Nikos and we'll look into the issues.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    ExecScriptFast() 09 Aug 2021 17:15 #19298

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • Robert,

    i don´t know what currently is supported or not, but here are some more test:

    cTest := String.Join(e"\n",<STRING>{;
    	"#INCLUDE 'XSharpDefs.xh'" ,; 
    	"&&   #INCLUDE 'Set.xh'",;	
    	"" ,; 
    	"SET CENTURY OFF" ,;
    	"? Today()" ,;
    	"SET EPOCH TO 1980" ,;
    	"? SetEpoch()" ,;
    	"" ,;
    	"RDDInfo ( Set.AutoOpen , true )",; 
    	"? 'AutoOpen' , RDDInfo ( Set.AutoOpen )" ,; 
    	"RDDInfo ( Set.AutoOrder , 1 )",;
    	"? 'AutoOrder' , RDDInfo ( Set.AutoOrder )" ,;
    	"?" ,;
    	"&&    SET DATE GERMAN" ,;
    	"&&    RDDInfo ( _SET_AUTOOPEN, true )" ,;  
    	"RETURN true" })	    
    	    
    	?
    	? cTest
    	? 
    	        
    	? "Script result:" , ExecScriptFast ( cTest )   	          
    	?

    what´s not working is e.g. something like
    SET DATE GERMAN
    RDDInfo ( _SET_AUTOOPEN, true )

    I also noticed that if the script contains 'RETURN', a value must be returned, otherwise a null reference exception is thrown.

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    ExecScriptFast() 13 Aug 2021 10:10 #19338

    • robert
    • robert's Avatar


  • Posts: 3448
  • Karl-Heinz,
    I will look into this to see what the problem is. I think the SCAN FOR problem is caused by the same problem that Juan reported for DbEval().
    Can you create a Github ticket for this, so it does not get forgotten ?

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    ExecScriptFast() 13 Aug 2021 21:05 #19349

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • robert wrote: Karl-Heinz,
    I will look into this to see what the problem is. I think the SCAN FOR problem is caused by the same problem that Juan reported for DbEval().
    Can you create a Github ticket for this, so it does not get forgotten ?

    Robert


    Robert,

    it´s already logged

    www.xsharp.eu/forum/public-vfp/2555-2-6a...e-replace-test#19309

    In the meantime Chris added another DBEval() sample to the mentioned Github ticket.

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    ExecScriptFast() 15 Aug 2021 11:24 #19362

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • some more samples ...

    - the first script catches a divide by zero exception.

    - the seconds script enforces a Macrocompiler error because i´m trying to assign a string to the local 'lOk' which is declared as logic. Use the

    "PRIVATE lOk" ,;

    declaration instead and you can assign to 'lOk' whatever you like ;-)

    cTest := String.Join(e"\n",<STRING>{;
    	"#INCLUDE 'XSharpDefs.xh'" ,;
    	"LOCAL lOk" ,;
    	"local n as int" ,;
    	"n := 0",;
    	"lOk := true" ,; 
    	"TRY" ,;
    	"?  'Try division 12/'+ntrim(n)" ,;
    	"?  'Result is:' , 12 / n" ,;
    	"CATCH e AS Exception",;
    	"?   e , ' happened'" ,;
    	"    lOk := false" ,;
    	"END TRY" ,;
    	"?" ,;  
    	"RETURN lOk" })
    	    
    	?
    	? cTest
    	? 
    	        
    	? "Script result:" , ExecScriptFast ( cTest )   	          
    	?
    	
            
    cTest := String.Join(e"\n",<STRING>{;
    	"#INCLUDE 'XSharpDefs.xh'" ,;
    	"LOCAL lOk as logic" ,;
    	"&&  PRIVATE lOk" ,;
    	"If true" ,;
    	"  lOk := 'text'",;
    	"else" ,; 
    	"  lOk := false",;
    	"endif" ,; 
    	"?",;
    	"RETURN lOk" })
    	
    	?
    	? cTest
    	? 
    	        
    	? "Script result:" , ExecScriptFast ( cTest )   	          
    	?	 

    I am impressed what´s already possible with the new script compiler !

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    Last edit: by Karl-Heinz.
    • Page:
    • 1