CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: MsgBox Problem

  1. #1
    Join Date
    Jul 2001
    Location
    British Columbia, Canada
    Posts
    19

    MsgBox Problem

    I can get a message box to pop up using the MsgBox Function, but if I try to add any other parameters besides the prompt, I get this:

    Compile error:
    Expected: =

    All I wanted was to specify the title. Here is the code I wrote:

    MsgBox("There is an error.", ,"WARNING")

    Can someone tell me what I'm doing wrong? Thanks.





    The more you know, the more you know you don't know.
    The more you know, the more you know you don't know.

  2. #2
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    Re: MsgBox Problem

    Try it like this...

    MsgBox "Message", , "Message Title"


  3. #3
    Join Date
    Jul 2001
    Location
    British Columbia, Canada
    Posts
    19

    Re: MsgBox Problem

    That worked perfectly, thanks! I guess it was those brackets hanging me up.





    The more you know, the more you know you don't know.
    The more you know, the more you know you don't know.

  4. #4
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: MsgBox Problem

    If you do want to use brackets, try this:

    Call MsgBox("There is an error.", ,"WARNING")

    This is because you use Option Explicit.


    Regards,

    Michi
    MCSE, MCDBA

  5. #5
    Join Date
    Jul 2001
    Location
    British Columbia, Canada
    Posts
    19

    Re: MsgBox Problem

    Cool, that works too! But I didn't type Option Explicit into my code. Could my VB design environment be using it automatically I wonder?





    The more you know, the more you know you don't know.
    The more you know, the more you know you don't know.

  6. #6
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: MsgBox Problem

    I made a mistake just now. It is VB system not "Option Explicit" that not allow brackets without "Call" when there is no return value or you don't want to get it. But in VB.NET, the need for the Call word will be removed. Let's look and see.


    Regards,

    Michi
    MCSE, MCDBA

  7. #7
    Join Date
    Mar 2001
    Location
    California
    Posts
    336

    Re: MsgBox Problem

    Yea, Option Explicit has nothing to do with brackets used in calling functions. Option Explicit has to do with variables being declared before initialization.

    Brackets will be used in calling a function when prefixed with the "Call" directive, or when used in an equasion. For example

    Call MsgBox("Hello World")

    Dim Response
    Response = MsgBox("Hello World")

    You should get used to using the "Call" directive and using brackets when calling functions. It is common in almost every other programming language, and will be implemented in VB.NET

    Good luck!

    John Peloquin
    Peloweb.com
    [email protected]

    "Always remember to lock your keys in your car so little elves don't come and steal them out of your pocket" - Alexander Graham Bell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured