Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do multiple conditions for single If statement

Tags:

vbscript

I'm trying to do two conditions on a single If statement in vbscript. Should be really simple, but it's not working. Something like:

 If Not (fileName = testFileName) & (fileName <> "") Then Else .... 

I'm making it two if statements to get it working, but can I do a not conditional with an "and" with another not condition?

like image 935
James Drinkard Avatar asked Sep 20 '11 18:09

James Drinkard


People also ask

Can you have 3 conditions in an if statement?

If you have to write an IF statement with 3 outcomes, then you only need to use one nested IF function. The first IF statement will handle the first outcome, while the second one will return the second and the third possible outcomes. Note: If you have Office 365 installed, then you can also use the new IFS function.

How do you write multiple if conditions?

Answer:To write your IF formula, you need to nest multiple IF functions together in combination with the AND function. As one final component of your formula, you need to decide what to do when none of the conditions are met.

Can we enter multiple if conditions in an IF formula?

While Excel will allow you to nest up to 64 different IF functions, it's not at all advisable to do so.


2 Answers

Use the 'And' keyword for a logical and. Like this:

If Not ((filename = testFileName) And (fileName <> "")) Then 
like image 139
Hogan Avatar answered Sep 26 '22 02:09

Hogan


As Hogan notes above, use an AND instead of &. See this tutorial for more info.

like image 35
JW8 Avatar answered Sep 26 '22 02:09

JW8