View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default Changing the name of a message box

But when you assign the result to a variable, it is no longer just
informational. It then becomes functional. Dave's response changed the
character of the statement.

"Rick Rothstein" wrote:

LOL... I just loved your response, it was perfect!

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
Dim Resp as long
resp = msgbox(Prompt:="are you sure you'd never want yes/no?",
buttons:=vbYesNo)

if resp = xlyes then
msgbox "Really?"
else
msgbox "I thought there'd be an instance"
end if

JLGWhiz wrote:

I'm trying to think of when I would want a Yes and No button on an
informational message box. Kind of like those things on a boar hog. <g

"Rick Rothstein" wrote:

Just to be clear, you are using MsgBox as a subroutine in Method 1 and
as a
function in Method 2 (you are testing a value that is returned from the
MsgBox call)... when used as a function, parentheses are required, when
used
as a subroutine, they are only mandatory when the Call keyword is used
and a
mistake to use otherwise. Here is the reason why as I explained it in
an old
posting of mine...

As others have shown without specifically pointing to the reason, your
problem stems from the parentheses. MsgBox is a function and when used
to
return a value, such as like this...

Answer = MsgBox("Here is a question", vbYesNo Or vbQuestion)

the parentheses are required. When no value is returned, the function
effectively becomes a subroutine. There are two proper ways to call a
subroutine...

Call MsgBox("Here is a question", vbYesNo Or vbQuestion)

and

MsgBox "Here is a question", vbYesNo Or vbQuestion

Note that when Call is used, the parentheses are required; however,
when the
Call keyword is omitted, the parentheses are syntactically incorrect.
So you
are probably asking, "Why did it work when I didn't add the 2nd
argument?"
Good question. It seems that when parentheses are used in a statement
that
are not required by syntax, VB assumes it has an expression to evaluate
and,
well, it attempts to evaluate the contents of the parentheses. When you
specified only a single text argument, VB could evaluate it... it
simply
evaluates as itself. But, when you added the 2nd argument, VB has no
mechanism to evaluate two expressions without an operator of some kind
between them (the comma is not an expression operator), so it generated
an
error. The bottom line is to use parentheses in a subroutine statement
**only** when they are required by syntax (do not use them to "pretty"
things up as doing that will create problems in more situations than
the one
I just outlined).

--
Rick (MVP - Excel)


"Patrick Molloy" wrote in
message
...
you can

method 1
msgbox, "hello World",vbyesno,"my message"


method 2
if msgbox( "Continue?",vbyesno,"Program check")=vbNo THEN
///quit code
else
///continue code
end if



"Bishop" wrote:

Ok, I see now. You can't use ()'s. Thanks.

"Patrick Molloy" wrote:

yes

the syntax is

msgbox prompt, buttons, title

VBA intellisence gives you the full list, but basically, whatever
you
use as
"title" will appear as the heading



"Bishop" wrote:

Can I change the name of a messege box to something other than
Microsoft Excel?



--

Dave Peterson