Connecting Tech Pros Worldwide Forums | Help | Site Map

Is there a problem with IIF or am I doing something wrong?

Charles May
Guest
 
Posts: n/a
#1: Nov 22 '05
I have a listview which checkboxes containing items to invoice. The Create
Invoice button (button1) is disabled unless there are items checked.
However, I had to use an if..then..else statement to make it work. My
question is, why can I not get it to work using an IIF statement?

In the mouseup event of the listview I tried the following methods to
achieve the result.


This doesn't work
IIF(Listview1.CheckedItems.Count > 0, Button1.Enabled = True,
Button1.Enabled = False)

This works

If Listview1.CheckedItems.Count > 0 Then
Button1.Enabled = True
Else
Button1.Enabled = False
End If

I'm just curious if I did something wrong trying to use IIF instead of
IF...THEN...ELSE

Thanks

Charlie



Mattias Sjögren
Guest
 
Posts: n/a
#2: Nov 22 '05

re: Is there a problem with IIF or am I doing something wrong?


Charles,
[color=blue]
>I'm just curious if I did something wrong trying to use IIF instead of
>IF...THEN...ELSE[/color]

IIF is not a built-in language statement, it's a function. And like
any other function, all the parameters you pass to it are evaluated,
and using = in that context performs comparison, not assignment.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#3: Nov 22 '05

re: Is there a problem with IIF or am I doing something wrong?


Charles,
In addition to Mattias's comments, have you considered simply using:

Button1.Enabled = (Listview1.CheckedItems.Count > 0)

Hope this helps
Jay

"Charles May" <quarantine1@hotmail.com> wrote in message
news:yB4Fb.101864$8y1.312337@attbi_s52...[color=blue]
> I have a listview which checkboxes containing items to invoice. The Create
> Invoice button (button1) is disabled unless there are items checked.
> However, I had to use an if..then..else statement to make it work. My
> question is, why can I not get it to work using an IIF statement?
>
> In the mouseup event of the listview I tried the following methods to
> achieve the result.
>
>
> This doesn't work
> IIF(Listview1.CheckedItems.Count > 0, Button1.Enabled = True,
> Button1.Enabled = False)
>
> This works
>
> If Listview1.CheckedItems.Count > 0 Then
> Button1.Enabled = True
> Else
> Button1.Enabled = False
> End If
>
> I'm just curious if I did something wrong trying to use IIF instead of
> IF...THEN...ELSE
>
> Thanks
>
> Charlie
>
>[/color]


Charles May
Guest
 
Posts: n/a
#4: Nov 22 '05

re: Is there a problem with IIF or am I doing something wrong?


Thanks Mattias.

It's working now with your help

Charlie
"Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message
news:%23FsOLs1xDHA.3436@tk2msftngp13.phx.gbl...[color=blue]
> Charles,
>[color=green]
> >I'm just curious if I did something wrong trying to use IIF instead of
> >IF...THEN...ELSE[/color]
>
> IIF is not a built-in language statement, it's a function. And like
> any other function, all the parameters you pass to it are evaluated,
> and using = in that context performs comparison, not assignment.
>
>
>
> Mattias
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.[/color]


Closed Thread