-
November 7th, 2018, 07:29 AM
#1
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
-
November 7th, 2018, 08:14 AM
#2
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.
-
November 7th, 2018, 09:35 AM
#3
Re: MessageBox not working in vb.ne
Thanks for your reply. The above suggested solution gives me an error on the 'show' word.
-
November 7th, 2018, 04:39 PM
#4
Re: MessageBox not working in vb.ne
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.
-
November 11th, 2018, 09:59 PM
#5
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.
-
November 11th, 2018, 10:01 PM
#6
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.
-
December 5th, 2018, 11:32 AM
#7
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)
-
December 5th, 2018, 12:32 PM
#8
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.
-
December 22nd, 2018, 01:52 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|