Closed majkaz closed 3 years ago
Hi! Thanks for the feedback!
The reference itself is not being Set
, so the result is legitimate, and the parameter can (arguably should) indeed be passed by value. oMail.Subject = ...
is not altering the object reference ByRef
/ByVal
is referring to, only a property of that object; passing the reference ByVal
would guarantee that the function cannot alter that reference as a side-effect.
Try adding Set oMail = Nothing
just before End Function
: with ByRef
the caller probably blows up with error 91 now, with ByVal
only the local pointer was (needlessly) nullified, and the calling code carries on without flinching!
My mistake, the issue can be closed.
I know I am dating myself, but I swear I am aware of the situation when referencing an object since the time I had to change my macros from WordBasic to VBA. Looking at the spaghetti mess I have accumulated in years, I had a brain freeze.
Rubberduck version information Version 2.5.1.5557 OS: Microsoft Windows NT 10.0.14393.0, x64 Host Product: Microsoft Outlook x86 Host Version: 16.0.4266.1001 Host Executable: OUTLOOK.EXE
Description As part of my old code, currently in refactoring, a MailItem is passed ByRef to a function and the function manipulates the subject if a condition is met. Inspection shows "Parameter can be passed by value".
The complete function for review:
In my understanding, this one is false positive.