help with messages

Hi Amigos,
I am new to VB.NET. I want to display a simple message on the screen. i have the following code:


Dim msg As String = "You have to fill in all the information provided"
Dim title As String = "Message"
msg = MsgBox(msg, MsgBoxStyle.Critical, title)

and this is the error I get when I try to execute this code.


It is invalid to show a modal dialog or form when the application is not running in UserInteractive mode. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.

please help.

Comments

  • [b][red]This message was edited by DrMarten at 2006-9-29 11:15:53[/red][/b][hr]
    : Hi Amigos,
    : I am new to VB.NET. I want to display a simple message on the screen. i have the following code:
    :
    :
    [code]
    [green][b]'Change this to.>>[/b]
    [/green]
    Dim msg As String = "You have to fill in all the information provided"
    Dim title As String = "Message"
    Dim result As MsgBoxResult
    result = MsgBox(msg, MsgBoxStyle.Critical, title)
    [green][b]'You had>>
    'msg=A function result i.e.
    'msg=msgbox(msg ...etc
    'do you see the error?[/b]
    [/green]

    [/code]
    :
    : and this is the error I get when I try to execute this code.
    :
    :
    : It is invalid to show a modal dialog or form when the application is not running in UserInteractive mode. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
    :
    : please help.
    ====================================================================

    Hi,

    [b][blue]You don't need the equal sign as in
    [code]
    result=MsgBox("Hello there!!", MsgBoxStyle.OKOnly, "Hello!")
    [/code]
    if your program doesn't need to store the result.
    [/blue][/b]

    Do the following [b] without the "=" sign.[/b]>>

    Simplest.>>
    [code]
    MsgBox("Hello there!!")
    [/code]

    Slightly longer.>>
    [code]
    'This gives the same result.>>
    MsgBox("Hello there!!", MsgBoxStyle.OKOnly)
    [/code]

    As the above two except the title-bar is given some text.>>
    [code]
    MsgBox("Hello there!!", MsgBoxStyle.OKOnly, "Hello!")
    [/code]

    Have fun coding!! :-) ;-)

    I've never had the error you describe.
    Have you stopped the program running from previously?


    Regards,

    Dr M.

    P.S.

    If you want a response passed back to your program then use it like the following Microsoft example.

    Example
    This example uses the MsgBox function to display a critical-error message in a dialog box with Yes and No buttons. The No button is specified as the default response. This is done by combining the MsgBox constant values into one numeric expression. In this case, adding 4 (the Yes/No button combination) and 16 (the Critical Message window) and 256 (the second button as default button) gives a total of 276. The value returned by the MsgBox function depends on the button chosen by the user: Yes returns a value of 6; No returns a value of 7.
    [code]
    Dim msg As String
    Dim title As String
    Dim style As MsgBoxStyle
    Dim response As MsgBoxResult
    msg = "Do you want to continue?" ' Define message.
    style = MsgBoxStyle.DefaultButton2 Or _
    MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
    title = "MsgBox Demonstration" ' Define title.
    ' Display message.
    response = MsgBox(msg, style, title)
    If response = MsgBoxResult.Yes Then ' User chose Yes.
    ' Perform some action.
    Else
    ' Perform some other action.
    End If
    [/code]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion