Boolean Question

  • Thread starter Thread starter Ray Batig
  • Start date Start date
R

Ray Batig

Greetings,

I am sure missing something but just can't see it. When I run the code

If ((NewProd <> "") And (NewProd <> Prod)) Or (DRun <= 30) Then
More code here
End If

and NewProd = "One", Prod = "One" and DRun = 5, the If passes to the More
code here.

I had previously used:

If ((NewProd <> "") And (NewProd <> Prod)) Or DRun <= 30 Then

If (NewProd <> "" And NewProd <> Prod) Or (DRun <= 30) Then

with the same results. To get this to work I ended up using:

If NewProd <> Prod Then
If (NewProd <> "") Or (DRun <= 30) Then

Would someone explain the error of my ways?

Thanks in advance for your help.

Ray
 
Of course it does.
You DRun is 5, so it's less than or equal to 30. The If condition evaluates
to True.
 
If I understand your question then you were close on your second attempt. It
is a brackets thing. (Boolean is not too easy to follow)

If (NewProd <> "") And (NewProd <> Prod Or DRun <= 30) Then

In the above NewProd <> "" must be true or the whole thing is false.
Either NewProd <> Prod Or DRun <= 30 must be true, otherwise the whole thing
is false...

Give it a try. I haven't but I think that is what you want...

HTH
 

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

Back
Top