I've been thinking about how some methods require parentheses while others don't and decided to look into why that was the cause. MSDN said that if the method returns a value AND you're not ignoring the returned value by forgoing a variable on the left hand side, then parentheses are necessary. However, even if the method has the capability of returning a value, you can remove the parentheses if you don't care what the value is.
Ex:
This would work
This would also work (although it wouldn't be very useful since you have no way of knowing how the user responded)
This would NOT work (method is returning a value but there are no parentheses)
This would give you a syntax error (parentheses indicates a returned value is expected but there is no variable for it
However, I found something I don't understand about this. I was using the attachments.add method (which is what started it all), and Excel accepts it with or without parentheses, regardless of whether or not you have a variable.
Ex:
This works even though there are parentheses and no variable
According to the MSDN, this method returns an attachment object. Even more confusing is that it will accept a variable with or without the "Set" statement even though it is an object.
Ex:
This works
And this works
When I hover over "outm" with my mouse, it shows as a string what the pathname is. Which I also don't get because usually nothing shows up for objects.
Does anyone have any insight?
Bookmarks