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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Arthur_WoodConnect With a Mentor Commented:
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
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
yes, the  <condition 1> AND <condition 2> will return true only if both conditions return true.
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
more compelte verion:

If result = 2  and time = 3  then
'do action1
else
' do action2
end if
0
 
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
All Courses

From novice to tech pro — start learning today.