Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MISSING PARENTHESIS Kanmi Excel Worksheet Functions 3 June 26th 09 10:51 PM
parenthesis puiuluipui Excel Discussion (Misc queries) 2 May 27th 08 01:59 PM
Short key for parenthesis - Hot key Anders Excel Discussion (Misc queries) 0 December 19th 07 09:09 AM
Parenthesis problem gmangrove Charts and Charting in Excel 1 December 21st 06 03:11 AM
WHAT ARE PARENTHESIS IN FORMULAS? ann New Users to Excel 2 August 21st 06 10:43 PM


All times are GMT +1. The time now is 07:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"