CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2018
    Posts
    6

    MessageBox not working in vb.ne

    Hi. I am trying to show a message informing the user that a file already exists and then exit the button code. I am getting an error on the MessageBox line. I have tried MessageBox. show but that gives an eoor also.

    Here is the code:

    Code:
    'Use filename chosen by user
            strFileName = lblChosenFile.Text
    
            strNewFileName = ForcastFileName(strFileName)
            If System.IO.File.Exists(strNewFileName) Then
                'The forcasted file exists
                'Delete the file
                'System.IO.File.Delete(strNewFileName)
                MessageBox = ("File has already been forcasted." a, "File Forcasted", vbOKOnly)
                Exit Sub
            End If

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MessageBox not working in vb.ne

    Your MessageBox syntax is incorrect. See the examples here: https://docs.microsoft.com/en-us/dot...ramework-4.7.2

    I'm not a vb.net coder, but it should look more like:
    Code:
    MessageBox.Show("File has already been forcasted.", "File Forcasted", MessageBoxButtons.Ok)
    Last edited by Arjay; November 7th, 2018 at 08:20 AM.

  3. #3
    Join Date
    Oct 2018
    Posts
    6

    Re: MessageBox not working in vb.ne

    Thanks for your reply. The above suggested solution gives me an error on the 'show' word.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MessageBox not working in vb.ne

    Quote Originally Posted by Valeriegn View Post
    Thanks for your reply. The above suggested solution gives me an error on the 'show' word.
    Well, what is the error? Try changing the MessageBoxButtons.Ok part to MessageBoxButtons.OK.

    If this doesn't work, post your code and the error.

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: MessageBox not working in vb.ne

    Have you by chance created a variable named MessageBox? If so that would cause an error when you add the .Show as variables do not have a show method. MessageBox does.

    Your original post also has an a in there that should not be there.
    Last edited by DataMiser; November 11th, 2018 at 10:02 PM.
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: MessageBox not working in vb.ne

    The older VB6 style code also works
    Code:
    msgBox "File has already been forcasted.", "File Forcasted"
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Nov 2018
    Posts
    4

    Re: MessageBox not working in vb.ne

    Already removed the a character after your message "File has already been forcasted." and behind the first comma?
    This command line is correct, as suggested by Arjay:
    Code:
    MessageBox.Show("File has already been forcasted.", "File Forcasted", MessageBoxButtons.Ok)

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: MessageBox not working in vb.ne

    What about the other things I pointed out? My guess would be that you have defined a variable or procedure that is overriding the messagebox call. You should search your code for messagebox and see if there are any declarations for it, if so then that would explain why it is not working.
    Always use [code][/code] tags when posting code.

  9. #9
    Join Date
    Dec 2018
    Posts
    15

    Re: MessageBox not working in vb.ne

    You may try this code:

    Private Sub cmdExit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdExit.Click
    Dim intresponse As DialogResult
    intresponse = MessageBox.Show("Are you sure you want to exit the program?",
    "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
    End Sub

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