×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Expression is not valid outside of WITH/ENDWITH

Expression is not valid outside of WITH/ENDWITH

Expression is not valid outside of WITH/ENDWITH

(OP)
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

RE: Expression is not valid outside of WITH/ENDWITH

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 .F. but you actually just wrote .F 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

RE: Expression is not valid outside of WITH/ENDWITH

By the way, you can greatly simplify the code. Something like this:

CODE -->

RTN = (opt=1 AND bk AND NOT cl) OR ;
       (opt=2 AND NOT bk AND cl) OR ;
       (opt=3 AND cl) 

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Expression is not valid outside of WITH/ENDWITH

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

CODE

IF bk = .t. and. cl = .f. 


and

CODE

IF bk = .f. and. 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
https://www.doschke.name

RE: Expression is not valid outside of WITH/ENDWITH

(OP)
thank you Mike,

i see that the .and. in the first and second if statement is missing the first dot

RE: Expression is not valid outside of WITH/ENDWITH

(OP)
thank you Olaf

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close