<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Test an Object and Its Property</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2010/07/21/test-an-object-and-its-property/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2010/07/21/test-an-object-and-its-property/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 23:42:03 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Tushar Mehta</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/21/test-an-object-and-its-property/#comment-48327</link>
		<dc:creator>Tushar Mehta</dc:creator>
		<pubDate>Mon, 26 Jul 2010 17:42:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4048#comment-48327</guid>
		<description>&lt;p&gt;A follow up to my original post.  Four different ways to handle the problem without worrying about bushy trees or duplicated code.  Do keep in mind that as Dick in his original post pointed out the value of these techniques is much more apparent in more realistic code than this small example.  In more realistic code, there might be several tests for validity not just the 2 as here.&lt;/p&gt;
&lt;p&gt;1) Recognize that booleans can be assigned the result of a test and don&#039;t require an If test with a corresponding assignment of a true/false value.&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container text default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;text codecolorer&quot;&gt;Sub useBool()&lt;br&gt;
&#160; &#160; Dim rControl As Range&lt;br&gt;
&#160; &#160; Dim Oops As Boolean&lt;br&gt;
&#160; &#160; Oops = rControl Is Nothing&lt;br&gt;
&#160; &#160; If Not Oops Then _&lt;br&gt;
&#160; &#160; &#160; &#160; Oops = Not IsEmpty(rControl.Offset(1, 0).Value)&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; If Not Oops Then&lt;br&gt;
&#160; &#160; &#160; &#160; &#039;update code&lt;br&gt;
&#160; &#160; Else&lt;br&gt;
&#160; &#160; &#160; &#160; &#039;error code&lt;br&gt;
&#160; &#160; &#160; &#160; End If&lt;br&gt;
&#160; &#160; End Sub&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;2) Use the boolean approach but skip the If Not Oops tests&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container text default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;text codecolorer&quot;&gt;Sub useBool2()&lt;br&gt;
&#160; &#160; Dim rControl As Range&lt;br&gt;
&#160; &#160; Dim Oops As Boolean&lt;br&gt;
&#160; &#160; Oops = rControl Is Nothing&lt;br&gt;
&#160; &#160; On Error Resume Next&lt;br&gt;
&#160; &#160; Oops = Oops Or Not IsEmpty(rControl.Offset(1, 0).Value)&lt;br&gt;
&#160; &#160; On Error GoTo 0&lt;br&gt;
&#160; &#160; &lt;br&gt;
&#160; &#160; If Not Oops Then&lt;br&gt;
&#160; &#160; &#160; &#160; &#039;update code&lt;br&gt;
&#160; &#160; Else&lt;br&gt;
&#160; &#160; &#160; &#160; &#039;error code&lt;br&gt;
&#160; &#160; &#160; &#160; End If&lt;br&gt;
&#160; &#160; End Sub&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;3) Use a GoTo as an error handler.  That&#039;s a limited application of the development philosophy that any forward-moving GoTo is OK. [GoTos become a nightmare when people jump back-and-forth with them.]&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container text default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;text codecolorer&quot;&gt;Sub useErrXIT()&lt;br&gt;
&#160; &#160; Dim rControl As Range&lt;br&gt;
&#160; &#160; If rControl Is Nothing Then GoTo ErrXIT&lt;br&gt;
&#160; &#160; If Not IsEmpty(rControl.Offset(1, 0).Value) Then _&lt;br&gt;
&#160; &#160; &#160; &#160; GoTo ErrXIT&lt;br&gt;
&#160; &#160; &#039;update code&lt;br&gt;
&#160; &#160; Exit Sub&lt;br&gt;
ErrXIT:&lt;br&gt;
&#160; &#160; MsgBox &quot;Oops&quot;&lt;br&gt;
&#160; &#160; End Sub&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;4) And, of course, one can enhance the above by using an Enum to better explain the error.&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container text default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;text codecolorer&quot;&gt;Sub useErrXIT2()&lt;br&gt;
&#160; &#160; Enum ErrCode&lt;br&gt;
&#160; &#160; &#160; &#160; NoError = 0&lt;br&gt;
&#160; &#160; &#160; &#160; NoObj&lt;br&gt;
&#160; &#160; &#160; &#160; NotEmpty&lt;br&gt;
&#160; &#160; &#160; &#160; End Enum&lt;br&gt;
&#160; &#160; Dim rControl As Range&lt;br&gt;
&#160; &#160; Dim Oops As ErrCode&lt;br&gt;
&#160; &#160; If rControl Is Nothing Then Oops = NoObj: GoTo ErrXIT&lt;br&gt;
&#160; &#160; If Not IsEmpty(rControl.Offset(1, 0).Value) Then _&lt;br&gt;
&#160; &#160; &#160; &#160; Oops = NotEmpty: GoTo ErrXIT&lt;br&gt;
&#160; &#160; &#039;update code&lt;br&gt;
&#160; &#160; Exit Sub&lt;br&gt;
ErrXIT:&lt;br&gt;
&#160; &#160; &#039;customized error message&lt;br&gt;
&#160; &#160; End Sub&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>A follow up to my original post.  Four different ways to handle the problem without worrying about bushy trees or duplicated code.  Do keep in mind that as Dick in his original post pointed out the value of these techniques is much more apparent in more realistic code than this small example.  In more realistic code, there might be several tests for validity not just the 2 as here.</p>
<p>1) Recognize that booleans can be assigned the result of a test and don&#8217;t require an If test with a corresponding assignment of a true/false value.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container text default">
<div style="white-space: nowrap;" class="text codecolorer">Sub useBool()<br />
&nbsp; &nbsp; Dim rControl As Range<br />
&nbsp; &nbsp; Dim Oops As Boolean<br />
&nbsp; &nbsp; Oops = rControl Is Nothing<br />
&nbsp; &nbsp; If Not Oops Then _<br />
&nbsp; &nbsp; &nbsp; &nbsp; Oops = Not IsEmpty(rControl.Offset(1, 0).Value)<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; If Not Oops Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &#8216;update code<br />
&nbsp; &nbsp; Else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &#8216;error code<br />
&nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; End Sub</div>
</div>
<p>2) Use the boolean approach but skip the If Not Oops tests</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container text default">
<div style="white-space: nowrap;" class="text codecolorer">Sub useBool2()<br />
&nbsp; &nbsp; Dim rControl As Range<br />
&nbsp; &nbsp; Dim Oops As Boolean<br />
&nbsp; &nbsp; Oops = rControl Is Nothing<br />
&nbsp; &nbsp; On Error Resume Next<br />
&nbsp; &nbsp; Oops = Oops Or Not IsEmpty(rControl.Offset(1, 0).Value)<br />
&nbsp; &nbsp; On Error GoTo 0<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; If Not Oops Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &#8216;update code<br />
&nbsp; &nbsp; Else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &#8216;error code<br />
&nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; End Sub</div>
</div>
<p>3) Use a GoTo as an error handler.  That&#8217;s a limited application of the development philosophy that any forward-moving GoTo is OK. [GoTos become a nightmare when people jump back-and-forth with them.]</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container text default">
<div style="white-space: nowrap;" class="text codecolorer">Sub useErrXIT()<br />
&nbsp; &nbsp; Dim rControl As Range<br />
&nbsp; &nbsp; If rControl Is Nothing Then GoTo ErrXIT<br />
&nbsp; &nbsp; If Not IsEmpty(rControl.Offset(1, 0).Value) Then _<br />
&nbsp; &nbsp; &nbsp; &nbsp; GoTo ErrXIT<br />
&nbsp; &nbsp; &#8216;update code<br />
&nbsp; &nbsp; Exit Sub<br />
ErrXIT:<br />
&nbsp; &nbsp; MsgBox &#8220;Oops&#8221;<br />
&nbsp; &nbsp; End Sub</div>
</div>
<p>4) And, of course, one can enhance the above by using an Enum to better explain the error.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container text default">
<div style="white-space: nowrap;" class="text codecolorer">Sub useErrXIT2()<br />
&nbsp; &nbsp; Enum ErrCode<br />
&nbsp; &nbsp; &nbsp; &nbsp; NoError = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; NoObj<br />
&nbsp; &nbsp; &nbsp; &nbsp; NotEmpty<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Enum<br />
&nbsp; &nbsp; Dim rControl As Range<br />
&nbsp; &nbsp; Dim Oops As ErrCode<br />
&nbsp; &nbsp; If rControl Is Nothing Then Oops = NoObj: GoTo ErrXIT<br />
&nbsp; &nbsp; If Not IsEmpty(rControl.Offset(1, 0).Value) Then _<br />
&nbsp; &nbsp; &nbsp; &nbsp; Oops = NotEmpty: GoTo ErrXIT<br />
&nbsp; &nbsp; &#8216;update code<br />
&nbsp; &nbsp; Exit Sub<br />
ErrXIT:<br />
&nbsp; &nbsp; &#8216;customized error message<br />
&nbsp; &nbsp; End Sub</div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tushar Mehta</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/21/test-an-object-and-its-property/#comment-48326</link>
		<dc:creator>Tushar Mehta</dc:creator>
		<pubDate>Mon, 26 Jul 2010 17:22:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4048#comment-48326</guid>
		<description>&lt;p&gt;Chris wrote: &quot;I hold that the VBA On Error statement should not appear in application code, since anything you can program for after the event you can program for before the event.&quot;&lt;/p&gt;
&lt;p&gt;For 95% of the code I write that is probably true -- not to mention that during development it is often a must that no error handler be enabled except for specific *anticipated* errors.&lt;/p&gt;
&lt;p&gt;But, it sometimes makes for extremely convoluted implementation of a fairly straightforward algorithm.  One instance where I use &#039;on error resume next&#039; extensively is in the context of an Excel chart.  At times detecting whether a certain property or method applies to the chart at hand is more work (requiring more cumbersome code that is harder to read, understand, and maintain) than simply making the change and falling through in the event of an error.  Not only does this make the code more streamlined but I don&#039;t have to worry about falling over when (if?) Microsoft introduces new chart types.&lt;/p&gt;
&lt;p&gt;And, there are a number of such instances where handling errors is easier than detecting the possibility of an error.  Not only with Excel but with other applications and in building web based solutions using, say, asp and javascript.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Chris wrote: &#8220;I hold that the VBA On Error statement should not appear in application code, since anything you can program for after the event you can program for before the event.&#8221;</p>
<p>For 95% of the code I write that is probably true &#8212; not to mention that during development it is often a must that no error handler be enabled except for specific *anticipated* errors.</p>
<p>But, it sometimes makes for extremely convoluted implementation of a fairly straightforward algorithm.  One instance where I use &#8216;on error resume next&#8217; extensively is in the context of an Excel chart.  At times detecting whether a certain property or method applies to the chart at hand is more work (requiring more cumbersome code that is harder to read, understand, and maintain) than simply making the change and falling through in the event of an error.  Not only does this make the code more streamlined but I don&#8217;t have to worry about falling over when (if?) Microsoft introduces new chart types.</p>
<p>And, there are a number of such instances where handling errors is easier than detecting the possibility of an error.  Not only with Excel but with other applications and in building web based solutions using, say, asp and javascript.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Greaves</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/21/test-an-object-and-its-property/#comment-48324</link>
		<dc:creator>Chris Greaves</dc:creator>
		<pubDate>Mon, 26 Jul 2010 14:01:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4048#comment-48324</guid>
		<description>&lt;p&gt;&quot;Shaking head in disbelief! Hasn&#039;t anyone heard of subroutines?&quot;&lt;br&gt;
I am about to take the first stray step off-topic, but yes, Tushar I&#039;ve heard of them. Daniel D McCracken&#039;s 1961 &quot;Guide to FORTRAN programming p 55-57? for example (grin!)&lt;/p&gt;
&lt;p&gt;I hold that the VBA On Error statement should not appear in application code, since anything you can program for after the event you can program for before the event.&lt;br&gt;
I do allow On Error statements to appear in library routines written by the senior developer (me!) to allow the application developer (me again!) to avoid On Error statements in applications.&lt;br&gt;
Many examples abound:&lt;br&gt;
(1) a procedure to determine the number of dimensions of an array (APL: &quot;rank&quot;)&lt;br&gt;
(2) a procedure to determine if a file exists (originally the good old FileLen statement test)&lt;br&gt;
(3) borderline cases such as this one:&lt;br&gt;
Public Function blnProcedureExistsInModule(strProcedureName As String, strModuleName As String, doc As Document) As Boolean&lt;br&gt;
    On Error Resume Next&lt;br&gt;
    If blnModuleExistsInDocument(doc, strModuleName) = True Then&lt;br&gt;
        blnProcedureExistsInModule = doc.VBProject.VBComponents(strModuleName) _&lt;br&gt;
        .CodeModule.ProcStartLine(strProcedureName, vbext_pk_Proc)  0&lt;br&gt;
    End If&lt;br&gt;
End Function&lt;/p&gt;
&lt;p&gt;Back on topic: That said, I suspect that sometimes it just makes more sense to have code in-line, that is, it can, at times, make the application code more comprehensible to future readers.&lt;/p&gt;
&lt;p&gt;We now return you to our regular programming ...&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>&#8220;Shaking head in disbelief! Hasn&#8217;t anyone heard of subroutines?&#8221;<br />
I am about to take the first stray step off-topic, but yes, Tushar I&#8217;ve heard of them. Daniel D McCracken&#8217;s 1961 &#8220;Guide to FORTRAN programming p 55-57? for example (grin!)</p>
<p>I hold that the VBA On Error statement should not appear in application code, since anything you can program for after the event you can program for before the event.<br />
I do allow On Error statements to appear in library routines written by the senior developer (me!) to allow the application developer (me again!) to avoid On Error statements in applications.<br />
Many examples abound:<br />
(1) a procedure to determine the number of dimensions of an array (APL: &#8220;rank&#8221;)<br />
(2) a procedure to determine if a file exists (originally the good old FileLen statement test)<br />
(3) borderline cases such as this one:<br />
Public Function blnProcedureExistsInModule(strProcedureName As String, strModuleName As String, doc As Document) As Boolean<br />
    On Error Resume Next<br />
    If blnModuleExistsInDocument(doc, strModuleName) = True Then<br />
        blnProcedureExistsInModule = doc.VBProject.VBComponents(strModuleName) _<br />
        .CodeModule.ProcStartLine(strProcedureName, vbext_pk_Proc)  0<br />
    End If<br />
End Function</p>
<p>Back on topic: That said, I suspect that sometimes it just makes more sense to have code in-line, that is, it can, at times, make the application code more comprehensible to future readers.</p>
<p>We now return you to our regular programming &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Greaves</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/21/test-an-object-and-its-property/#comment-48323</link>
		<dc:creator>Chris Greaves</dc:creator>
		<pubDate>Mon, 26 Jul 2010 13:51:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4048#comment-48323</guid>
		<description>&lt;p&gt;&quot; ... I cannot foresee any instance where relying on the case statements to execute in order would be error pron&quot;&lt;br&gt;
and Tushar&#039;s &quot;Hasn&#039;t anyone heard of subroutines?&quot;.&lt;/p&gt;
&lt;p&gt;Interpretation and Compilation are two sides of the generic &quot;translation&quot;, and any fear of future methods of translation are valid fears (not to say that they will come true, just that they are arguable).&lt;/p&gt;
&lt;p&gt;I suspect the easiest way for VBAers to see this is to take Tushar&#039;s approach and write a small procedure to handle these awkward tests. I do that often. When I take a chained AND condition and embed it into a VBA procedure, I become the translator, it is MY decision as to which condition is evaluated first, and which condition is evaluated conditionally on the first.&lt;/p&gt;
&lt;p&gt;Thus you and I could translate the same condition in two different ways.&lt;/p&gt;
&lt;p&gt;That said, is all the more reason for using Libraries of utility code rather than duplicating code.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>&#8221; &#8230; I cannot foresee any instance where relying on the case statements to execute in order would be error pron&#8221;<br />
and Tushar&#8217;s &#8220;Hasn&#8217;t anyone heard of subroutines?&#8221;.</p>
<p>Interpretation and Compilation are two sides of the generic &#8220;translation&#8221;, and any fear of future methods of translation are valid fears (not to say that they will come true, just that they are arguable).</p>
<p>I suspect the easiest way for VBAers to see this is to take Tushar&#8217;s approach and write a small procedure to handle these awkward tests. I do that often. When I take a chained AND condition and embed it into a VBA procedure, I become the translator, it is MY decision as to which condition is evaluated first, and which condition is evaluated conditionally on the first.</p>
<p>Thus you and I could translate the same condition in two different ways.</p>
<p>That said, is all the more reason for using Libraries of utility code rather than duplicating code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Chickering</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/21/test-an-object-and-its-property/#comment-48321</link>
		<dc:creator>Charles Chickering</dc:creator>
		<pubDate>Mon, 26 Jul 2010 13:16:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4048#comment-48321</guid>
		<description>&lt;p&gt;From what I understand, VBA is not a compiled language, rather it is interpreted line by line as it is processed, thus for VBA, I cannot foresee any instance where relying on the case statements to execute in order would be error prone.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>From what I understand, VBA is not a compiled language, rather it is interpreted line by line as it is processed, thus for VBA, I cannot foresee any instance where relying on the case statements to execute in order would be error prone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tushar Mehta</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/21/test-an-object-and-its-property/#comment-48319</link>
		<dc:creator>Tushar Mehta</dc:creator>
		<pubDate>Mon, 26 Jul 2010 07:21:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4048#comment-48319</guid>
		<description>&lt;p&gt;Shaking head in disbelief!  Hasn&#039;t anyone heard of subroutines? {grin}  Why go through this song-and-dance when the &quot;multiple steps&quot; could be black-boxed as a subroutine or a function?  Add the appropriate arguments to this procedure to get custom error messages.&lt;/p&gt;
&lt;p&gt;As an aside, while the Select Case True approach is very appealing, I&#039;ve learned the hard way (harking back to my FORTRAN and assembler days) to not rely on the sequence in which a particular compiler generates code.  In VBA it seems like it has been sequential (top to bottom, left to right) for as long as I remember but who knows?  If Microsoft ever provides a graceful transition from VBA to the .Net world, the compiler rules may change.&lt;/p&gt;
&lt;p&gt;In any case, here&#039;s how I&#039;ve handled these kinds of scenarios.  Reverse the tests to get a much simpler structure that also allows one to provide more informative error messages.  This technique to removing &quot;bushy trees&quot; is one of the few things I still remember from &#039;The Elements of Programming Style&#039; by Kernighan and Plauger (http://www.amazon.com/Elements-Programming-Style-Brian-Kernighan/dp/0070342075/ref=sr_1_2?ie=UTF8&amp;s=books&amp;qid=1280125164&amp;sr=8-2), which IMO is a must read for anyone who aspires to anything more than just using the macro recorder.&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container text default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;text codecolorer&quot;&gt;&#160; &#160; Dim rControl As Range&lt;br&gt;
&#160; &#160; If rControl Is Nothing Then&lt;br&gt;
&#160; &#160; &#160; &#160; MsgBox &quot;rControl is not defined&quot;&lt;br&gt;
&#160; &#160; ElseIf Not IsEmpty(rControl.Offset(0, 1).Value) Then&lt;br&gt;
&#160; &#160; &#160; &#160; &#039;should it be _&lt;br&gt;
&#160; &#160; &#160; &#160; &#160;application.WorksheetFunction.CountA(rcontrol.Offset(0,1).Resize(1,7)) &lt;&gt;0&lt;br&gt;
&#160; &#160; &#160; &#160; MsgBox &quot;Target Cell &quot; &amp; rControl.Offset(0, 1).Address &amp; &quot; is not empty&quot;&lt;br&gt;
&#160; &#160; Else&lt;br&gt;
&#160; &#160; &#160; &#160; rControl.Offset(0, 1).Resize(1, 7).Value = clsTimeSheet.TimeArray&lt;br&gt;
&#160; &#160; &#160; &#160; End If&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Alternatively, simulate Try...Catch...Finally though I don&#039;t like it all that much because it also traps errors in the 1st MsgBox and the assignment.&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container text default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;text codecolorer&quot;&gt;Sub Try_Catch_Finally()&lt;br&gt;
&#160; &#160; Dim rControl As Range&lt;br&gt;
&#160; &#160; On Error GoTo Catch1&lt;br&gt;
&#160; &#160; If Not IsEmpty(rControl.Offset(0, 1).Value) Then&lt;br&gt;
&#160; &#160; &#160; &#160; MsgBox &quot;Target Cell &quot; &amp; rControl.Offset(0, 1).Address &amp; &quot; is not empty&quot;&lt;br&gt;
&#160; &#160; Else&lt;br&gt;
&#160; &#160; &#160; &#160; rControl.Offset(0, 1).Resize(1, 7).Value = clsTimeSheet.TimeArray&lt;br&gt;
&#160; &#160; &#160; &#160; End If&lt;br&gt;
&#160; &#160; GoTo Finally1&lt;br&gt;
Catch1:&lt;br&gt;
&#160; &#160; MsgBox &quot;rControl is not defined&quot;&lt;br&gt;
&#160; &#160; Resume Finally1&lt;br&gt;
Finally1:&lt;br&gt;
&#160; &#160; End Sub&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>Shaking head in disbelief!  Hasn&#8217;t anyone heard of subroutines? {grin}  Why go through this song-and-dance when the &#8220;multiple steps&#8221; could be black-boxed as a subroutine or a function?  Add the appropriate arguments to this procedure to get custom error messages.</p>
<p>As an aside, while the Select Case True approach is very appealing, I&#8217;ve learned the hard way (harking back to my FORTRAN and assembler days) to not rely on the sequence in which a particular compiler generates code.  In VBA it seems like it has been sequential (top to bottom, left to right) for as long as I remember but who knows?  If Microsoft ever provides a graceful transition from VBA to the .Net world, the compiler rules may change.</p>
<p>In any case, here&#8217;s how I&#8217;ve handled these kinds of scenarios.  Reverse the tests to get a much simpler structure that also allows one to provide more informative error messages.  This technique to removing &#8220;bushy trees&#8221; is one of the few things I still remember from &#8216;The Elements of Programming Style&#8217; by Kernighan and Plauger (<a href="http://www.amazon.com/Elements-Programming-Style-Brian-Kernighan/dp/0070342075/ref=sr_1_2?ie=UTF8&#038;s=books&#038;qid=1280125164&#038;sr=8-2" rel="nofollow">http://www.amazon.com/Elements-Programming-Style-Brian-Kernighan/dp/0070342075/ref=sr_1_2?ie=UTF8&#038;s=books&#038;qid=1280125164&#038;sr=8-2</a>), which IMO is a must read for anyone who aspires to anything more than just using the macro recorder.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container text default">
<div style="white-space: nowrap;" class="text codecolorer">&nbsp; &nbsp; Dim rControl As Range<br />
&nbsp; &nbsp; If rControl Is Nothing Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; MsgBox &#8220;rControl is not defined&#8221;<br />
&nbsp; &nbsp; ElseIf Not IsEmpty(rControl.Offset(0, 1).Value) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &#8216;should it be _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;application.WorksheetFunction.CountA(rcontrol.Offset(0,1).Resize(1,7)) &lt;&gt;0<br />
&nbsp; &nbsp; &nbsp; &nbsp; MsgBox &#8220;Target Cell &#8221; &amp; rControl.Offset(0, 1).Address &amp; &#8221; is not empty&#8221;<br />
&nbsp; &nbsp; Else<br />
&nbsp; &nbsp; &nbsp; &nbsp; rControl.Offset(0, 1).Resize(1, 7).Value = clsTimeSheet.TimeArray<br />
&nbsp; &nbsp; &nbsp; &nbsp; End If</div>
</div>
<p>Alternatively, simulate Try&#8230;Catch&#8230;Finally though I don&#8217;t like it all that much because it also traps errors in the 1st MsgBox and the assignment.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container text default">
<div style="white-space: nowrap;" class="text codecolorer">Sub Try_Catch_Finally()<br />
&nbsp; &nbsp; Dim rControl As Range<br />
&nbsp; &nbsp; On Error GoTo Catch1<br />
&nbsp; &nbsp; If Not IsEmpty(rControl.Offset(0, 1).Value) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; MsgBox &#8220;Target Cell &#8221; &amp; rControl.Offset(0, 1).Address &amp; &#8221; is not empty&#8221;<br />
&nbsp; &nbsp; Else<br />
&nbsp; &nbsp; &nbsp; &nbsp; rControl.Offset(0, 1).Resize(1, 7).Value = clsTimeSheet.TimeArray<br />
&nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; GoTo Finally1<br />
Catch1:<br />
&nbsp; &nbsp; MsgBox &#8220;rControl is not defined&#8221;<br />
&nbsp; &nbsp; Resume Finally1<br />
Finally1:<br />
&nbsp; &nbsp; End Sub</div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Greaves</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/21/test-an-object-and-its-property/#comment-48239</link>
		<dc:creator>Chris Greaves</dc:creator>
		<pubDate>Fri, 23 Jul 2010 14:58:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4048#comment-48239</guid>
		<description>&lt;p&gt;Dick, I&#039;d go with Bob Smith (&quot;Isn&#039;t it generally bad to rely on assumptions that case, if, etc. clauses are executed in order?&quot;) but that&#039;s just showing my age.&lt;br&gt;
In The Good Old Days(TM) when we were restricted to FORTRAN and COBOL, we wrote some FORTRAN code that worked just fine on machine CDC, but when we moved it to machine Honeywell it failed. The reason was often enough a different implementation by the writers of the compilers.&lt;br&gt;
I think that today when we are writing in, say, VBA which is specifically for the Microsoft family of products, we have less risk.&lt;br&gt;
I suspect that my MIX C compiler (1985) may have taken some liberties that would easily demonstrate Bob&#039;s concerns.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Dick, I&#8217;d go with Bob Smith (&#8220;Isn&#8217;t it generally bad to rely on assumptions that case, if, etc. clauses are executed in order?&#8221;) but that&#8217;s just showing my age.<br />
In The Good Old Days(TM) when we were restricted to FORTRAN and COBOL, we wrote some FORTRAN code that worked just fine on machine CDC, but when we moved it to machine Honeywell it failed. The reason was often enough a different implementation by the writers of the compilers.<br />
I think that today when we are writing in, say, VBA which is specifically for the Microsoft family of products, we have less risk.<br />
I suspect that my MIX C compiler (1985) may have taken some liberties that would easily demonstrate Bob&#8217;s concerns.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fzz</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/21/test-an-object-and-its-property/#comment-48221</link>
		<dc:creator>fzz</dc:creator>
		<pubDate>Thu, 22 Jul 2010 23:12:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4048#comment-48221</guid>
		<description>&lt;p&gt;@Bob - If the language in question specifies operation order, then it should be safe to assume that operation order. FTHOI, you also need to consider associativity and whether or not some operators evaluate both operands or not (e.g., 0 as left hand side for multiplication means the right hand side really doesn&#039;t need to be evaluated).&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Bob &#8211; If the language in question specifies operation order, then it should be safe to assume that operation order. FTHOI, you also need to consider associativity and whether or not some operators evaluate both operands or not (e.g., 0 as left hand side for multiplication means the right hand side really doesn&#8217;t need to be evaluated).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fzz</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/21/test-an-object-and-its-property/#comment-48220</link>
		<dc:creator>fzz</dc:creator>
		<pubDate>Thu, 22 Jul 2010 22:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4048#comment-48220</guid>
		<description>&lt;p&gt;Ah, the lack of short-circuit Boolean evaluation.&lt;/p&gt;
&lt;p&gt;C-like/spawned languages have &amp;&amp; [and] and &#124;&#124; [or] operators which perform short-circuit Boolean evaluation. That is, if the left side of &amp;&amp; (&#124;&#124;) is false (true), then the result of the &amp;&amp; (&#124;&#124;) expression must be false (true), so no need to evaluate the right side. These are (in C semantics) strictly Boolean operations with both sides converted to 1/TRUE if nonzero or left as 0/FALSE before the comparisons are performed.&lt;/p&gt;
&lt;p&gt;OTOH, VBA&#039;s And and Or (and Xor, etc) operators are BITWISE operators rather than Boolean operators. They&#039;re performing operations on ALL bits from BOTH SIDES of the operators, so both sides must be evaluated. Royal PITA.&lt;/p&gt;
&lt;p&gt;You could always use boolean state variables to approximate short-circuit boolean evaluation.&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container vb default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;vb codecolorer&quot;&gt;&lt;span class=&quot;co1&quot;&gt;&#039;condition1 AND condition2 AND . . . AND conditionN&lt;br&gt;
&lt;/span&gt;state = &lt;span class=&quot;kw1&quot;&gt;False&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; condition1 &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; condition2 &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; . . . &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; conditionN &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; state = &lt;span class=&quot;kw1&quot;&gt;True&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; state &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; perform operation&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt;&lt;br&gt;
&#160; exception handling&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;co1&quot;&gt;&#039;condition1 OR condition2 OR . . . OR conditionN&lt;br&gt;
&lt;/span&gt;state = &lt;span class=&quot;kw1&quot;&gt;True&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Not&lt;/span&gt; condition1 &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Not&lt;/span&gt; condition2 &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; . . . &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;Not&lt;/span&gt; conditionN &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt; state = &lt;span class=&quot;kw1&quot;&gt;False&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt; state &lt;span class=&quot;kw1&quot;&gt;Then&lt;/span&gt;&lt;br&gt;
&#160; perform operation&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;Else&lt;/span&gt;&lt;br&gt;
&#160; exception handling&lt;br&gt;
&lt;span class=&quot;kw1&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;If&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>Ah, the lack of short-circuit Boolean evaluation.</p>
<p>C-like/spawned languages have &amp;&amp; [and] and || [or] operators which perform short-circuit Boolean evaluation. That is, if the left side of &amp;&amp; (||) is false (true), then the result of the &amp;&amp; (||) expression must be false (true), so no need to evaluate the right side. These are (in C semantics) strictly Boolean operations with both sides converted to 1/TRUE if nonzero or left as 0/FALSE before the comparisons are performed.</p>
<p>OTOH, VBA&#8217;s And and Or (and Xor, etc) operators are BITWISE operators rather than Boolean operators. They&#8217;re performing operations on ALL bits from BOTH SIDES of the operators, so both sides must be evaluated. Royal PITA.</p>
<p>You could always use boolean state variables to approximate short-circuit boolean evaluation.</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container vb default">
<div style="white-space: nowrap;" class="vb codecolorer"><span class="co1">&#8216;condition1 AND condition2 AND . . . AND conditionN<br />
</span>state = <span class="kw1">False</span></p>
<p><span class="kw1">If</span> condition1 <span class="kw1">Then</span> <span class="kw1">If</span> condition2 <span class="kw1">Then</span> . . . <span class="kw1">If</span> conditionN <span class="kw1">Then</span> state = <span class="kw1">True</span></p>
<p><span class="kw1">If</span> state <span class="kw1">Then</span><br />
&nbsp; perform operation<br />
<span class="kw1">Else</span><br />
&nbsp; exception handling<br />
<span class="kw1">End</span> <span class="kw1">If</span></p>
<p><span class="co1">&#8216;condition1 OR condition2 OR . . . OR conditionN<br />
</span>state = <span class="kw1">True</span></p>
<p><span class="kw1">If</span> <span class="kw1">Not</span> condition1 <span class="kw1">Then</span> <span class="kw1">If</span> <span class="kw1">Not</span> condition2 <span class="kw1">Then</span> . . . <span class="kw1">If</span> <span class="kw1">Not</span> conditionN <span class="kw1">Then</span> state = <span class="kw1">False</span></p>
<p><span class="kw1">If</span> state <span class="kw1">Then</span><br />
&nbsp; perform operation<br />
<span class="kw1">Else</span><br />
&nbsp; exception handling<br />
<span class="kw1">End</span> <span class="kw1">If</span></div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dick Kusleika</title>
		<link>http://www.dailydoseofexcel.com/archives/2010/07/21/test-an-object-and-its-property/#comment-48189</link>
		<dc:creator>Dick Kusleika</dc:creator>
		<pubDate>Thu, 22 Jul 2010 14:24:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=4048#comment-48189</guid>
		<description>&lt;p&gt;I hadn&#039;t heard that Bob.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I hadn&#8217;t heard that Bob.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

