0

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?

codetalker
  • 576
  • 1
  • 6
  • 21
  • Visual Studio is not used to code in Visual Basic 6, add the correct tag and remove the meaningless ones thanks – Steve Jun 21 '15 at 08:54
  • 1
    For your info., there was a "Visual Studio 6.0" too. – codetalker Jun 21 '15 at 08:57
  • Anyways, I am doing it – codetalker Jun 21 '15 at 08:58
  • 1
    possible duplicate of [VBA does not accept my method calling and gives Compile error: Syntax error](http://stackoverflow.com/questions/15040060/vba-does-not-accept-my-method-calling-and-gives-compile-error-syntax-error) – GSerg Jun 21 '15 at 08:59
  • @GSerg, can you tell me how is it a duplicate of that? – codetalker Jun 21 '15 at 09:01
  • Because you need to remove the parentheses @Siddhant, otherwise [you are trying to pass as a first argument something in parentheses that has two variables in it, which doesn't make sense for the parser](http://stackoverflow.com/a/15040102/11683). – GSerg Jun 21 '15 at 09:02
  • Thanks a lot @GSerg, I understand it now... – codetalker Jun 21 '15 at 09:04

1 Answers1

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

GregHNZ
  • 7,946
  • 1
  • 28
  • 30