View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Tricky data type error

Well, I definitely have seen a compile error with this.
Thanks for confirming it can't be caught normally at compile time.

RBS

"Chip Pearson" wrote in message
...
I've never seen a situation in which that code wouldn't compile. Of
course, it blows up at run-time, but it should compile.

No, there's no way to catch such errors when you write or compile the
code.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"RB Smissaert" wrote in message
...
Was caught out by something tricky that I thought might be worth it to
pass on.

Had coded, simplified, this code:

Sub test()

Dim strTest As String

If strTest = 4 Then
MsgBox strTest
End If

End Sub

Strangely, this sometimes compiles and sometimes doesn't.
Unfortunately, it did with me, but it can't run as there obviously will
be an error:
Type mismatch (Error 13)
Strangely also it can sometimes run on Excel 2003, but as far as I can
see never on 2000.
Just completely unpredictable.

Would there be a way to catch out this coding error reliably at compile
time?


RBS