Evaluation of an 'Cond1 AND Cond2 AND Cond3' statement

W

Wilfried Poerschke

Dear members,

in a statement like

IF Cond1 AND Cond2 AND Cond3 THEN....

which condition is evaluated first by ACCESS?
I would be really glad if somebody would know.

Thank You

and greetings from Berlin

Wilfried
 
M

Matthias Klaey

Dear members,

in a statement like

IF Cond1 AND Cond2 AND Cond3 THEN....

which condition is evaluated first by ACCESS?
I would be really glad if somebody would know.

Thank You

and greetings from Berlin

Wilfried

The most important thing is that *all* conditions are evaluated. Thus,
if Cond1 is False, still Cond2 and Cond3 will be evaluated. There is
not "shortuct boolean evaluation" in Access or VB/VBA. Otherwise,
expressions are being evaluated from left to right, IIRC.

If, say Cond2 depends on the result of Cond1, you need to take the If
statement apart:

If Cond1 Then
If Cond2 Then

...

HTH
Matthias Kläy
 
T

Tim Ferguson

The most important thing is that *all* conditions are evaluated.

Just to add to this, the help files say explicitly that the order in
which they will be evaluated is not defined.

If the order matters, then you have to program it so:

If cond1 Then
If cond2 Then
If cond3 Then
'do something
End If : End If : End If

HTH

Tim F
 
M

Matthias Klaey

Just to add to this, the help files say explicitly that the order in
which they will be evaluated is not defined.
[...]

Hi Tim
could you give a reference where you found this statement?
I only found the "operator precedence" section where it is explicitely
said that + and - as well as * and / are executed left-to-right if on
the same precedence level.

With kind regards
Matthias Kläy
 
T

Tim Ferguson

could you give a reference where you found this statement?
I only found the "operator precedence" section where it is explicitely
said that + and - as well as * and / are executed left-to-right if on
the same precedence level.

.... but does not say anything about the order of evaluation of the
operands. I think I'll have to say fair cop on this, although it's
something I've always 'known' and must have read it 'somewhere'... :-(

My book references seem completely silent on the subject, so if nothing
else it'll remind me actually to look things up before quoting them

Nevertheless, as a matter of form, if the order mattered (say, because of
side effects of function or method calls), I would still chop them all up
into separate statements to make sure.

All the best


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top