Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Syntax checking
Message
From
27/11/2001 05:52:44
 
 
To
27/11/2001 05:13:38
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00586184
Message ID:
00586195
Views:
18
Pascal,
The only way I can think of is to COMPILE the code and check for an .ERR file. This seems to work, but unfortunately requires the COMPILE command which was not available in the runtime before VFP6 SP5 (I think). Anyway, here's a simple syntax checker that returns the compiler's error message if there's a syntax error, otherwise a blank:
?SyntaxChecker("BROWSE") && returns ''
?SyntaxChecker("BORWSE") && returns 'BORWSE'
                                    'Error in line 1: Unrecognized command verb.'

PROCEDURE SyntaxChecker
LPARAMETERS tcCode

lcTempPrg = AddBs(SYS(2023)) + "A" + RIGHT(SYS(3), 7) + ".TMP"
lcErrFile = FORCEEXT(lcTempPrg, "ERR")

STRTOFILE(tcCode, lcTempPrg)
COMPILE (lcTempPrg)

IF FILE(lcErrFile)
   *-- an error occurred
   lcRetVal = FILETOSTR(lcErrFile)
ELSE
   lcRetVal = ""
ENDIF

*-- cleanup
DELETE FILE (FORCEEXT(lcTempPrg, "*") )

RETURN lcRetVal
HTH
>How can I check if a command contained in a string has valid syntax, whithout executing it. Thought it was possible, but can't find how (VFP 5.0).
>
>I have a program that dynamically builds a query, so I want to know if the query has correct syntax before executing it.
Daniel
Previous
Reply
Map
View

Click here to load this message in the networking platform