What in the world is my prof trying to say? Dealing with MsgBox

  • Thread starter Thread starter James
  • Start date Start date
J

James

What does this mean?

'To specify more than the first argument, you must use the MsgBox
function in an expression'


I'd love to see an example. Thanks!
 
Hello James,

Sounds like your prof was smokin a lil too much wacky tobaccy that day.

-Boo
 
The following specifies three arguments for a msgbox and it works fine as a
standalone statement:

MsgBox("Get a new Prof", MsgBoxStyle.Critical Or MsgBoxStyle.OKOnly, "Bad
Prof")
 
First of all, if you are studying VB.NET, I would think your professor
should be teaching you about the MessageBox class, rather than the MsgBox
function.

Second, it sounds like he/she is saying that if you want to use more than
just the first argument of the MsgBox function (the prompt or message
itself), you'd need to be using the MsgBox function inside of another
expression. That's not true though. Although many of the additional
parameters of the MsgBox function lend themselves to getting a return value
(and thus, you may want to capture that return value by using this function
inside of another expression), you don't necessarially have to capture the
return value. For example:

MsgBox "message", "something"

I think what he/she should have said was "When using MsgBox as a function
(where the arguments are specified inside of parenthesis), you are implying
that you want the return value of the function and so should use MsgBox()
inside of another expression, such as:

Dim i As Integer
i = MsgBox("Are you hungry", "Question", vbYesNo)
 
Scott M. said:
First of all, if you are studying VB.NET, I would think your professor
should be teaching you about the MessageBox class, rather than the MsgBox
function.

Since the MsgBox function is part of the Visual Basic Language, it is totally appropriate.
Second, it sounds like he/she is saying that if you want to use more than
just the first argument of the MsgBox function (the prompt or message
itself), you'd need to be using the MsgBox function inside of another
expression. That's not true though. Although many of the additional
parameters of the MsgBox function lend themselves to getting a return value
(and thus, you may want to capture that return value by using this function
inside of another expression), you don't necessarially have to capture the
return value. For example:

MsgBox "message", "something"

That won't work since the second argument is not a string. So it would look something like:

MsgBox("message", MsgBoxStyle.OkCancel, "something")

I think what he/she should have said was "When using MsgBox as a function
(where the arguments are specified inside of parenthesis), you are implying
that you want the return value of the function and so should use MsgBox()
inside of another expression, such as:

Dim i As Integer
i = MsgBox("Are you hungry", "Question", vbYesNo)

i = MsgBox("Are you hungry", vbYesNo, "Question")

or
i = MsgBox("Are you hungry", MsgBoxStyle.YesNo, "Question")
 
Back
Top