Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

how to make if behave differently



if xxx() AND yyy() then...

Is there any alternative if that does not evaluate the yyy if xxx is false?
0
kamleshmistry
Asked:
kamleshmistry
  • 2
3 Solutions
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If xxx() AndAlso yyy() Then

End If

If xxx() OrElse yyy() Then

End If
0
 
ClifCommented:
Simple...

If xxx() Then
    If yyy()
        'Only if xxx() and yyy() are true
    End If
End If
0
 
ClifCommented:
Ok, let's try the proper syntax...

If xxx() Then
    If yyy() Then
        'Only if xxx() and yyy() are true
    End If
End If
0
 
ptakjaCommented:
AndAlso and OrElse are new keywords in VB.Net that short circuit compound conditionals if a preceding expression evaluates to false.  These can be combined to more than 2 expressions as:

If xxx() AndAlso yyy() AndAlso zzz() Then

End If

In this case the only way zzz get evaluated is if xxx and yyy are both true.

Jeff
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now