Krishiyers
Krishiyers

Reputation: 1

Please solve and explain

This is a vbscript code. Please solve this and give me the reason.

a = 10
b =10
c = empty
d= empty
Msgbox a=b=c=d 

Expected result False. Actual result True. Pls explain how.

Regards Krishnan

Upvotes: 0

Views: 375

Answers (2)

Joachim Weiß
Joachim Weiß

Reputation: 407

All comparison operators are evaluated from left to right and have the same precedence. The problem here is that "empty=false". If you want to check whether a var is really empty you have to use the isEmpty function. In a logical comparison empty=false.

Ergo your expression is evaluated:

1. a=b [true]
2. (a=b)=c [false] because c is empty and false
3. ((a=b)=c)=d  because d is false and 2. is false

Ergo false=false that is true ;-)

Upvotes: 4

Don
Don

Reputation: 87

What you might consider trying is using something like this:

a = 10
b =10
c = empty
d= empty
Msgbox a=b AND a=c AND a=d

I think that the code that you have is causing an assignment rather than a comparison. Even though VBScript uses the = sign for both, an assignment will always return true.

Upvotes: 0

Related Questions