Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Parenthesis - to use or not to use?
Greetings all
Quick question - In John Green et al's Excel 2000 VBA I find the following assertion: "The general rule is that if you want to capture the return value of a function, you need to put any argument in parenthesis. If you don't want to use the return value, you should not use parenthesis." The first sentence is of course a nonnegotiable point of syntax - but what about the second sentence? I was under the impression that it is 100% a matter of taste if I write msgbox "Hello world" or msgbox("Hello world"), but the word "should" above suggests that there is a principled reason to drop parenthesis if not needed. Is there? In particular, does the computer in some sense process a non-returned value if you include parenthesis but not otherwise, so that a small performance hit attaches itself to parenthesis? Also, what about sub calls when there is no return value to worry about? If it is just a matter of taste I'll stick to parenthesis since it seems somehow more logical to me. Thank you for your time. -John Coleman |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Parenthesis - to use or not to use?
I would say that if your subsequent code depends on a
response from the user, eg: if msgbox ("Hello World?", vbquestion+vbyesno) = vbyes then then you need to use parenthesis or you get a syntax error, but if you are displaying the msgbox for information purposes then they are not necessary. eg msgbox "Hello World", vbinformation -----Original Message----- Greetings all Quick question - In John Green et al's Excel 2000 VBA I find the following assertion: "The general rule is that if you want to capture the return value of a function, you need to put any argument in parenthesis. If you don't want to use the return value, you should not use parenthesis." The first sentence is of course a nonnegotiable point of syntax - but what about the second sentence? I was under the impression that it is 100% a matter of taste if I write msgbox "Hello world" or msgbox("Hello world"), but the word "should" above suggests that there is a principled reason to drop parenthesis if not needed. Is there? In particular, does the computer in some sense process a non- returned value if you include parenthesis but not otherwise, so that a small performance hit attaches itself to parenthesis? Also, what about sub calls when there is no return value to worry about? If it is just a matter of taste I'll stick to parenthesis since it seems somehow more logical to me. Thank you for your time. -John Coleman . |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Parenthesis - to use or not to use?
John,
You, of course, can do what you want, but you should consider the future readers of your code. If I am looking at code and see MsgBox(..... then I start looking for the return value and its use. Without the ( )s I know that it is only being used for display purposes. HTH, Bernie MS Excel MVP "John Coleman" wrote in message om... Greetings all Quick question - In John Green et al's Excel 2000 VBA I find the following assertion: "The general rule is that if you want to capture the return value of a function, you need to put any argument in parenthesis. If you don't want to use the return value, you should not use parenthesis." The first sentence is of course a nonnegotiable point of syntax - but what about the second sentence? I was under the impression that it is 100% a matter of taste if I write msgbox "Hello world" or msgbox("Hello world"), but the word "should" above suggests that there is a principled reason to drop parenthesis if not needed. Is there? In particular, does the computer in some sense process a non-returned value if you include parenthesis but not otherwise, so that a small performance hit attaches itself to parenthesis? Also, what about sub calls when there is no return value to worry about? If it is just a matter of taste I'll stick to parenthesis since it seems somehow more logical to me. Thank you for your time. -John Coleman |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Parenthesis - to use or not to use?
I believe MSGBOX was an example of using parenthesis and not the focus. In
the second paragraph read the last three sentences and you'll actually understand the question at hand. -- Toby Erkson Oregon, USA Excel 2002 in Windows XP then I start looking for the return value and its use. Without the ( )s I know that it is only being used for display purposes. .... In particular, does the computer in some sense process a non-returned value if you include parenthesis but not otherwise, so that a small performance hit attaches itself to parenthesis? Also, what about sub calls when there is no return value to worry about? |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Parenthesis - to use or not to use?
Thanks to everyone for their replies. I figured out on the nature of
my error. For my own subroutines I always call them using the call keyword, in which parenthesis are required. I pretty much use message boxes only for debugging purposes, and with 1 parameter () are ignored. A little experimentation shows that 2 or more parameters with () as I have been doing leads to problems. My way to think about it now - msgbox( , , ..) is a noun that must be embedded in a bigger context to make sense, but in msgbox "hello world" msgbox is now functioning as a verb. In my defense - when I type msgbox in the VBA editor the IntelliSense which pops up suggests (), and sinse my code was compiling no-problem I didn't realize I was being ungrammatical. It is strange how you can misunderstand a basic feature of a language but nevertheless get by with your own idiosyncratic work-arounds. sub thanks() MsgBox Prompt := "Now I understand", Title:= "Thanks again" end sub -John Coleman |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
MISSING PARENTHESIS | Excel Worksheet Functions | |||
parenthesis | Excel Discussion (Misc queries) | |||
Short key for parenthesis - Hot key | Excel Discussion (Misc queries) | |||
Parenthesis problem | Charts and Charting in Excel | |||
WHAT ARE PARENTHESIS IN FORMULAS? | New Users to Excel |