Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Not getting "argument type mismatch"
Hello,
When I compile the following code, I get a "Byref argument type mismatch", which is exactly what I'd expect to get. Sub test1() Dim l As Long l = 3 test2 l End Sub Sub test2(s As String) 'do someting End Sub So my question is, why don't I get a compile error on this bit of code? I thought my Excel had become corrupted, but I tried it on other machines, same results - no compile error. Sub test1() Dim r As Range Set r = Range("a1") test2 r End Sub Sub test2(w As Worksheet) 'do someting End Sub Thank you, Regards DaveU |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Not getting "argument type mismatch"
Dave Unger wrote:
Hello, When I compile the following code, I get a "Byref argument type mismatch", which is exactly what I'd expect to get. Sub test1() Dim l As Long l = 3 test2 l End Sub Sub test2(s As String) 'do someting End Sub So my question is, why don't I get a compile error on this bit of code? I thought my Excel had become corrupted, but I tried it on other machines, same results - no compile error. Sub test1() Dim r As Range Set r = Range("a1") test2 r End Sub Sub test2(w As Worksheet) 'do someting End Sub Thank you, Regards DaveU try that Sub test1() Dim r As Range Set r = Range("a1") Set r = Nothing test2 r End Sub Sub test2(w As Worksheet) 'do someting End Sub Do you see why it is not compile error? It is because range and worksheet can be "compatible" if value is nothing. Variable value can be determined only at runtime. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Not getting "argument type mismatch"
Hi Witek,
Thanks for your reply. Sub test1() Dim r As Range Set r = Range("a1") Set r = Nothing test2 r End Sub Sub test2(w As Worksheet) 'do someting End Sub Do you see why it is not compile error? I think so, need to "ponder" this a while. It is because range and worksheet can be "compatible" if value is nothing.. Variable value can be determined only at runtime. This all came to my attention because I'd changed the argument in test2 from a range to worksheet (actual project very large), and was counting on the compiler to flag all the calling procedures I'd need to modify. You've given me food for thought, I don't think I've ever encountered (or noticed??) this before. Thank you, DaveU |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Not getting "argument type mismatch"
Dave Unger wrote:
Hi Witek, Thanks for your reply. Sub test1() Dim r As Range Set r = Range("a1") Set r = Nothing test2 r End Sub Sub test2(w As Worksheet) 'do someting End Sub Do you see why it is not compile error? I think so, need to "ponder" this a while. It is because range and worksheet can be "compatible" if value is nothing. Variable value can be determined only at runtime. This all came to my attention because I'd changed the argument in test2 from a range to worksheet (actual project very large), and was counting on the compiler to flag all the calling procedures I'd need to modify. You've given me food for thought, I don't think I've ever encountered (or noticed??) this before. Thank you, DaveU That will be happening with all procedures where arguments are objects. I usually add dummy argument to procedure. Compiler will catch that. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Not getting "argument type mismatch"
Hi witek,
That will be happening with all procedures where arguments are objects. I've been doing this for a few years now, and while not pretending to be an expert by any stretch of the imagination, I did think I had this arguments area pretty much "cased" - just goes to show that one never stops learning, and there's always more! I usually add dummy argument to procedure. Compiler will catch that. Good tip! Thanks. Regards DaveU |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
"ByRef argument type mismatch" error | Excel Programming | |||
"Compile Error: ByRef argument type mismatch" when calling my function from another module | Excel Programming | |||
HELP "ByRef Argument Type Mismatch" | Excel Programming | |||
"ByRef argument type mismatch" Error | Excel Programming | |||
"FIND" generates "Type mismatch" error | Excel Programming |