Hi.
This has been around for a long time. I posted a long time ago on Oberon Place but it's still there.
This causes crash in all versions.It's still here in X6.
Sub test() Dim s As Shape, sr As New ShapeRange sr.Add sEnd Sub
Yes I know s should not be nothing but sometimes when testing code you might lose your object or it doesn't even get set for reason of other errors from either program glitches or user coding error. This will cause unnecessary program crashes when one is testing/debugging code. Please fix so it doesn't crash.
It's more stable similar function AddRange can take anything without causing the program to crash.
~John
Caused me some headaches too, so I do things like this...
If Not s Is Nothing then sr.Add s
...or more often than not I send it to an error handler to help with debugging or a prevent a crash.
Steve said:If Not s Is Nothing then sr.Add s
In cases where I had to loop through a dynamic ShapeRange, even "Not s Is Nothing" didn't work for me. When I had Shapes deleted from a ShapeRange during runtime, the Locals window in the VBA editor was constantly saying "The referenced Shape doesn't exist anymore", so I used
If Not s Is Empty Then ...
I assume a shape is passed by reference in a ShapeRange, so it was better to check if the referenced object (the deleted Shape) is empty rather than nothing, cause the reference pointer was still there, but no object to fill it. Maybe this can help anyone in the future.
mo said:In cases where I had to loop through a dynamic ShapeRange, even "Not s Is Nothing" didn't work for me. When I had Shapes deleted from a ShapeRange during runtime, the Locals window in the VBA editor was constantly saying "The referenced Shape doesn't exist anymore", so I used
Me too. I think I recall this not working all the time.
mo said:If Not s Is Empty Then ...
Cool. Never tried that.
mo said: If Not s Is Empty Then ...
Haven't tried that one either, so will give it a shot. Thanks!
RunFlaCruiser said:I think I recall this not working all the time.
I would not suggest to recall it. VBA should not crash on this anyway. At least logically:
It is like giving a bag (the variable) of cookies (the internal object) to my girlfriend (the procedure or function). She doesn't have the right to separate from me (the crash), if the cookie bag is empty. A slap (an error message) would do it.
HI Mo.
Can I have some of that beer too!
lol.
ROFL
German beer is quite good, but not for the purpose I think you ascribe to me...
Cheers