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
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)
Re: MessageBox not working in vb.ne
Thanks for your reply. The above suggested solution gives me an error on the 'show' word.
Re: MessageBox not working in vb.ne
Quote:
Originally Posted by
Valeriegn
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.
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.
Re: MessageBox not working in vb.ne
The older VB6 style code also works
Code:
msgBox "File has already been forcasted.", "File Forcasted"
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)
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.
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