Tricky data type error
Strangely (at least to me) this runs:
Sub test()
Dim strTest As String
strTest = 2
If strTest = 4 Then
MsgBox strTest
End If
End Sub
But this doesn't:
Sub test()
Dim strTest As String
strTest = "a"
If strTest = 4 Then
MsgBox strTest
End If
End Sub
This might in fact explain the different behaviour on the different
machines, rather than the Excel version.
RBS
"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
|