msgbox

  • Thread starter Thread starter Jo
  • Start date Start date
J

Jo

Hi
Why does this not work?
MsgBox("message", vbYesNo, "title")
If I do this it does
a = MsgBox("message", vbYesNo, "title")
Why do I need to assign the result to a variable?
Thanks
Jo
 
Jo

just remove the brackets ...

MsgBox "message", vbYesNo, "title"

Regards

Trevor
 
Hi Jo,

You don't have to assign the MsgBox to a variable, but the fact that you
specify Yes and No buttons is giving the user a choice, and so it is
reasonable to assume you are interested in that response.

MsgBox is a function, which means that it returns a result. You can capture
the value returned or ignore it if you want, but the syntax is different
depending upon your choice.

For all Functions, if you want to capture the value, it is

result = Function _Call([arg1[, arge2[, arg3[, ...]]]])

If you don'r want to capture the return value, you omit the brackets

Function _Call [arg1[, arge2[, arg3[, ...]]]]

Thus in your case, either of the following works, although in the second
case you will never know whichj button was pressed

a = MsgBox("message", vbYesNo, "title")

MsgBox "message", vbYesNo, "title"

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top