iif not working

G

Guest

hey all,

i'm using an iif and it's not working how I think it should work (go figure).
Anyway,

IIf(IsNothing(Request.QueryString("Sd")), Me.sortDir = "asc",
Request.QueryString("Sd"))

When i run this the expression evaluates as true but the true part doesn't
happen for some reason. It's like it's broke or something.

Does anyone have Bill Gates' home phone number? I really need to ask him
about this one.

thanks,
rodchar
 
M

Marina

That is because in the True part, you are doing a comparison to a string.
You should expect that will result in True or False.

What are you expecting exactly? Can you please provide complete details on
what you expect to happen and what is happening, as well as the value of all
variables involved.
 
G

Guest

i thought i was doing an assignment statement?


Marina said:
That is because in the True part, you are doing a comparison to a string.
You should expect that will result in True or False.

What are you expecting exactly? Can you please provide complete details on
what you expect to happen and what is happening, as well as the value of all
variables involved.
 
M

Marina

IIF is a function. You are passing parameters to that function. Whenever
there is a method call, all the arguments are evaluated. Meaning the = sign
will be treated as a comparison operator, not the assignment operator.

Not only that, but all the arguments will be evaluated no matter if the
condition that is the first argument is true or false. This is because IIF
is not a language construct - it is a function. So all arguments will be
evaluated before they are called. This is unlike constructs in C#,
javascript, and other languages where there is an actual language construct
for this that evaluates the true part or false part only if necessary.
 
G

Guest

thank you this helped.

Marina said:
IIF is a function. You are passing parameters to that function. Whenever
there is a method call, all the arguments are evaluated. Meaning the = sign
will be treated as a comparison operator, not the assignment operator.

Not only that, but all the arguments will be evaluated no matter if the
condition that is the first argument is true or false. This is because IIF
is not a language construct - it is a function. So all arguments will be
evaluated before they are called. This is unlike constructs in C#,
javascript, and other languages where there is an actual language construct
for this that evaluates the true part or false part only if necessary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top