Title of Message box not setting up

2019-09-17 07:28发布

问题:

I am writing some code in Visual Basic 6. It also uses the Msgbox funtion. Now I searched this and I got to know that if you want to set the title of the Message box then this is the syntax:

Msgbox(<Prompt>,<Title>)

For example, I write this:

MsgBox ("Incorrect Answer!","QM")

It says:

Compile Error Expected: =

Can someone tell me what is the problem?

回答1:

With VB6, you can either request a response, and do something based on the answer, or you can simply display a message.

If you want to know what button was clicked, you need to use the function format - that is, you must use the brackets.

If you simply want to display a message, then you don't use the brackets.

So if you want to just display the message, then continue, do this:

MsgBox "Incorrect Answer!", , "QM"

But if you want to know which button the user clicked (e.g. to offer them a try again, cancel, then you need a variable, and you use the brackets to signifify that it's a function:

Dim response = MsgBox("Try again?", MsgBoxStyle.YesNo, "QM")

You can then look at the response variable to find out which button the user clicked.

A couple of pages for reference:

http://vb6reference.tomswebdesign.net/msgbox.html

https://msdn.microsoft.com/en-us/library/139z2azd(v=vs.90).aspx