D
Dick Watson
Here's what I want to code:
...
If myobj Is Nothing Or myobj.property Is Null Then
Do_Lots
Of_Stuff
When_We
Get_Here
End If
...
Of course, this doesn't work because even if the first clause (myobj Is
Nothing) is True, VBA wastes time evaluating the second clause
(myobj.property Is Null) which, also of course, fails with object variable
not set.
So, here's how I coded it instead:
...
If myobj Is Nothing Then
boolDoStuff = True
ElseIf myobj.property Is Null Then
boolDoStuff = True
Else
boolDoStuff = False
End If
If boolDoStuff Then
Do_Lots
Of_Stuff
When_We
Get_Here
End If
...
(If it weren't for all of the context I'd need to pass, the obvious other
way--besides some harmful GoTos or error trapping--would have been
...
If myobj Is Nothing Then
Call DoStuff
ElseIf myobj.property Is Null Then
Call DoStuff
End If
...
Sub DoStuff ()
Do_Lots
Of_Stuff
When_We
Get_Here
End Sub
My question: is there a better way to get the evaluation done lazily in the
first place?
...
If myobj Is Nothing Or myobj.property Is Null Then
Do_Lots
Of_Stuff
When_We
Get_Here
End If
...
Of course, this doesn't work because even if the first clause (myobj Is
Nothing) is True, VBA wastes time evaluating the second clause
(myobj.property Is Null) which, also of course, fails with object variable
not set.
So, here's how I coded it instead:
...
If myobj Is Nothing Then
boolDoStuff = True
ElseIf myobj.property Is Null Then
boolDoStuff = True
Else
boolDoStuff = False
End If
If boolDoStuff Then
Do_Lots
Of_Stuff
When_We
Get_Here
End If
...
(If it weren't for all of the context I'd need to pass, the obvious other
way--besides some harmful GoTos or error trapping--would have been

...
If myobj Is Nothing Then
Call DoStuff
ElseIf myobj.property Is Null Then
Call DoStuff
End If
...
Sub DoStuff ()
Do_Lots
Of_Stuff
When_We
Get_Here
End Sub
My question: is there a better way to get the evaluation done lazily in the
first place?