#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Use of IIF

Thanks all for the responses. If you will bear with me, I will précis what I
have got from these
responses.

Hank Scorpio, apart from not realising that he also is venerated within
these NGs, would not use them by choice, preferring self-documenting, easily
maintainable code, and feels that breaking If ... Else ... Endif over
several lines and indenting supports that approach..

Rob Bovey made a similar point, but typical of Rob, he actually knew that
IIF is considerably slower, something the rest of us may have suspected, but
maybe know! He also made the point that it is limited to single statement
clauses.

Mark Bigelow also made the point that debugging is easier if the code is
split across multiple lines.

Another significant drawback of IIF was made by Dana DeLouis, namely that
both expressions are evaluated in an IIF, which could lead to problems. VBA
does not support short-circuiting., although Dana does use this construct.

Tushar Mehta chipped in with his view that if it supports the natural
thought process, he would use it. But more interestingly, IMO, was Tushar's
clearly laid out continuation of this thought, where he showed other
examples of his premise.This also prompted support from Wild Bill in that it
allows you to see more code at a time.

Bob's thought:

Thanks everyone for these thoughts, I found them useful

I tend to align to Hank's views, the maintainability is more important than
speed in most cases in these mega-mega processing paradigms we meet today,
and this is better served with multi-line, separate If statements.

Rob's point re performance, his point about single statement clauses, Mark's
observation on debugging, and Dana's point regarding the evaluation of IIF
expressions, all of these added to Hank's initial point, and it doesn't
leave much going for IIF in my opinion.

I have never been much of a user of this construct, but I think that from
now on I will relegate it to the memory, and not use it again. I will
however, pick up on some of Tushar's points, they made a lot of sense to me.

Thanks again everyone for these contributions.

Bob


"Bob Phillips" wrote in message
...
A question for my venerated colleagues in these newsgroups.

One of the threads that came up today led me to thinking about the IIF
function. For example, this simple test

If iCol 26 Then
col = Chr(iCol \ 26 + 64) & Chr(iCol Mod 26 + 64)
Else
col = Chr(iCol + 64)
End If

can also be written using IIF as

col = IIf(iCol 26, Chr(iCol \ 26 + 64) & Chr(iCol Mod 26 + 64),
Chr(iCol + 64))

My view is that whilst the second is shorter, and often a more obvious
statement (as in this case?) of what is happening, it can often be quite

the
opposite, and be very confusing. As I tend to like to keep to a certain
style, for instance I always use If ... End If even for single statements,

I
tend not to use it.

But is this wasteful prejudice? Do you guys use it? What are your views on
this topic? Where does it come from, is it likely to be supported

evermore?
Do you care?

Look forward to hearing from you.

--

HTH

Bob Phillips





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"