View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz[_2_] JLGWhiz[_2_] is offline
external usenet poster
 
Posts: 1,565
Default Changing the name of a message box

Right, when it does nothing but deliver a message, it is informational.
When it returns a value to a variable it is functional. So, if you do not
expect a response from the user, the there is no need for a Yes, No or
Cancel, or Question option. The Information, Exclamation and Critical could
still be cogent options. The OK button will show up if no other button is
specified.


"Rick Rothstein" wrote in message
...
Oh, I see what you mean... I used vbYesNo as part of the MsgBox example in
my caution. When you said "informational", you meant when called as a
subroutine... for that usage, you are right, there would be no need for
anything but the default OK button because there will be no code examining
the response. My caution about the parentheses still applies though (you
just wouldn't be modifying the number of buttons when specifying multiple
arguments). My example should have been something like this instead...

MsgBox "Doing that may cause a problem!", vbExclamation"

--
Rick (MVP - Excel)


"JLGWhiz" wrote in message
...
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