View Single Post
  #1   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

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