Jonathan
Jonathan

Reputation: 15432

Logic in IF statement

Can anybody tell me what the following logic would do?

if ((intOne and intTwo) = intThree)

I've got a feeling it checks that either intOne or intTwo matches intThree, but I'd like to know for certain. Unfortunately Google doesn't seem to have much support at all when it comes to asp classic.

Thank you in advance.

Upvotes: 0

Views: 2798

Answers (4)

Euro Micelli
Euro Micelli

Reputation: 34008

MSDN is pretty specific:

The And operator also performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table:
... (truth table for AND follows)

So the expression bitwise-ANDs the first two ints, and then compares the result to the third int.

Here's the same evaluation in C, for comparison.

if( (intOne & intTwo) == intThree ) ...

Upvotes: 6

Rob Allen
Rob Allen

Reputation: 17719

My VBScript is a bit rusty, but I would guess that the (intOne and intTwo) section evaluates to true. My thinking is that it's only checking if the vars exist.

If you want to achieve an either or, it would probably look more like:

If intOne = intThree OR intTwo = intThree Then
  ...
End If

If both need to be equal to intThree then you would do

If intOne = intThree AND intTwo = intThree Then
  ...
End If

Upvotes: 1

scartag
scartag

Reputation: 17680

As far as i know .. the 'and' operator in vbscript is a boolean operator .. which means intOne and intTwo should be expressions or values that result in boolean.

Wrong syntax i think ...

Upvotes: 1

capdragon
capdragon

Reputation: 14899

I don't think the syntax is correct, but the logic is saying if BOTH intOne and IntTwo equal intThree then ...

if intOne = intThree and intTwo = intThree

Upvotes: 0

Related Questions