MsgBox - Function versus Action

wilderfan

Registered User.
Local time
Yesterday, 16:41
Joined
Mar 3, 2008
Messages
172
I have been told that MsgBox can be both a function and an action.

What is the simplest way to distinguish between when it is being used as a function versus when it is being used as an action?
 
Simplest? Who knows.

If you just want to display a message with an OK button, just call MsgBox().

If you want to get a return value from MsgBox() (and change program flow with it), set it equal to a variable and set the button types you want in the correct parameter. Then check the variable against the vb constants to see which button was pressed.

I guess the "simplest" way to tell is if the "which buttons" parameter is filled in. Another way would be to see if it is just called or if it is set to a variable or use in an if statement.
 
an easy way is to see if there is an if word or an equals sign, which also clarified the usage.

so

msgbox("Hello World") just displays a string, with an OK button to close the box

but

result = msgbox("Do you want to do this",vbyesno)

asks the question and gives you buttons labelled yes and no to pick from, and stores the answer in a variable called result

and

if msgbox("Do you want to do this",vbyesno) = vbno then
dosomething
else
dosomethingelse
end if

asks the same question but immediately reacts to the button click without storing the result
 
Actually...

Msgbox "Hello world"

Is the "display only"/action option.... While adding the brackets makes it a function
Difference beeing with the () it will return a (function) value, while without it will not return anything.

Thus...
Msgbox "Hello world"
or
Result = Msgbox("Hello world")

while this
Msgbox("Hello world")
Is invalid, as the returned value is not stored/used anywhere.
 
I add brackets to everything automatically. I am just used to seeing arguments inside brackets. Background of many years use of Pascal. I keep getting reminded of the technical difference between no brackets and brackets

However

msgbox ("Hello world") is not an error - it does compile and work.

[edited - gawd, this is so slow today]

but

msgbox ("Hello world", vbinformation) IS AN ERROR

and I realise i normally use

CALL msgbox ("Hello world", vbinformation)

because I cant get out of the habit of using brackets.
 
Last edited:
So it does :(

I am sure it USED to error in like 97 or even 2.0? But in XP, confirmed it works... though "by fault" but it works :)
 

Users who are viewing this thread

Back
Top Bottom