If else statement

I'm trying to write an if else statement in which the action would perform if two conditions where true.
example:
If result = 2, and time = 3, then
 
LVL 3
trbazeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
in VBA:


If result = 2  and time = 3  then

Open in new window

0
trbazeAuthor Commented:
Is that the way it is actually written?  So that both conditions must return true on the if part of the statement.  Not just one.
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
yes, the  <condition 1> AND <condition 2> will return true only if both conditions return true.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Mike EghtebasDatabase and Application DeveloperCommented:
more compelte verion:

If result = 2  and time = 3  then
'do action1
else
' do action2
end if
0
Arthur_WoodCommented:
In .NET the If statement is a bit clearer:

If Result = 2 ANDALSO Time = 3 then

This does what is call 'short-circuiting' the If test.

In Access syntax

If Result = 2 and Tiime = 3 then

Both Tests are evaluated, even in the case where the First test FAILS (thsu making the value of the second test irrelevant).  In the .NET syntax, if the First test FAILS, then the second test is NOT evaluated.

Similary, in the negative test

If Result <> 2 or Time <> 3 then

The .NET syntax is

If Result <> 2 ORELSE Time <> 3 then

In the Access form, both tests will be evaluated, even when Result is in fact <> 2 (so that the result of the second test is once again irrelevant).  In the .NET syntax, only the the case where Result is actually equal to 2, will the second test be evaluated.

AW
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RyanProject Engineer, ElectricalCommented:
Theres some other ways.
If you just happen to care, while we're point out .net and VBA.

Excel uses an AND function.  IF(AND(result=2,time=3),"Was true","Was False")

In VBA you can implement an AND by nested IFs

If Result = 2 then
  if time = 3 then
    'both were true
  end if
end if
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.