Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expression is not valid outside of WITH/ENDWITH 1

Status
Not open for further replies.

Akourou

Programmer
Mar 28, 2019
34
GR
hello,

i get this error when i call this function:

Code:
FUNCTION bookopt
LPARAMETERS bk , cl, opt
IF opt=1
        IF bk = .t. and. cl = .f.
           RTN=.t.
        ELSE 
           RTN=.f.
        ENDIF 
ENDIF 
IF opt=2
        IF bk = .f. and. cl = .f.
           RTN=.t.
        ELSE 
           RTN=.f.
        ENDIF 
ENDIF 
IF opt=3
        IF cl = .t.
           RTN=.t.
        ELSE 
           RTN=.f.
        ENDIF 
ENDIF  
RETURN rtn
ENDFUNC

any ideas?

thank you
 
I can't see it form your code, but the most likely explanation is that you are missing a dot at the end of a word. For example, if you meant to write [tt].F.[/tt] but you actually just wrote [tt].F [/tt] then you would get that error. That's because VFP would be interpret the dot as part of the containership path of a property or method, which would only be valid in WITH/ENDWITH.

If you still can't see it, check to see which line triggered the error.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Besides how much you can shorten this code, it may speak for maintainability, but you simply have an and. there:

Code:
IF bk = .t. [highlight #FCE94F]and.[/highlight] cl = .f.

and

Code:
IF bk = .f. [highlight #FCE94F]and.[/highlight] cl = .f.

Either you write .and. or and without the dots. It's very legacy style to write .AND. and .OR. etc.
If you miss a dot there this will actually be taken to mean AND .c1, the parser/compiler is generous with whitespace, and as Mike already said a syntax like .property or .objectname only is available as the error tells you in WIDHT/ENDWITH. You didn't mean something like that, but you have it there.

Bye, Olaf.

Olaf Doschke Software Engineering
 
thank you Mike,

i see that the .and. in the first and second if statement is missing the first dot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top