-
MSGBOX not displaying, OK being automatically selected.
As per the Title, I can only assume I have set some kind of option without realising I have done so, but some MSGBOXes work !!!
This works ...
Code:
If ComboBox1.SelectedItem = Nothing Then myErrorMsg = "No League Selected"
MsgBox(myErrorMsg, MsgBoxStyle.Exclamation)
Exit Sub
End If
This, however, does NOT work & I get a message on the right hand side of the screen that says
Quote:
User Prompt: Clicked "OK" The user clicked the "OK Button in the MessageBox
Code:
If File.Exists(myRARfile) Then
ZipTest()
Else
myErrorMsg = "ERROR - Aborting ..."
MsgBox(myErrorMsg, vbCritical)
MSWord.Quit()
Exit Sub
End If
This is very frustrating :confused:, so if somebody can tell me what on earth is going on here, I'll be eternally grateful !!!
-
Re: MSGBOX not displaying, OK being automatically selected.
There is no setting that I know of which could cause that behavior automatically. How can you tell this is happening? If you were to put a breakpoint on the MsgBox line, would the breakpoint be hit? What would happen if you stepped forward one line?
The next thing to try would be putting the breakpoint on the MSWord.Quit() line. If the MsgBox is being automatically accepted, the breakpoint should be reached without the MsgBox showing up.
-
Re: MSGBOX not displaying, OK being automatically selected.
Well there's nothing in the code that explains it. Do you have any kind of automated keypresses, clicks etc. going on either in this program or another running concurrently with it. I notice that you have a live Word application so is that possibly a source or recipient of such an event?
-
Re: MSGBOX not displaying, OK being automatically selected.
Quote:
Originally Posted by
Shaggy Hiker
How can you tell this is happening?
I am in Debug mode and I run the program ... that's what it does ... I am baffled (though obviously not an expert ...) !!!
This is the start of the program, it's quite straightforward ...
Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
' Ensure that valid data is entered into the DropDown Boxes
If ComboBox1.SelectedItem = Nothing Then
myErrorMsg = "No League Selected"
MsgBox(myErrorMsg, MsgBoxStyle.Exclamation)
Exit Sub
End If
If ComboBox2.SelectedItem = Nothing Then
myErrorMsg = "No Session Selected"
MsgBox(myErrorMsg, MsgBoxStyle.Exclamation)
Exit Sub
End If
'Data has been validated, so Input Form can be closed
Me.Close()
'Set important variables
myLeague = ComboBox1.SelectedItem
mySession = ComboBox2.SelectedItem
myFolder = myNlFolder + ComboBox1.SelectedItem
'Ensure there is a Newsletters Folder for this league & a Current Season Folder inside that Folder ...
'This should never be a problem, as the Outlook Newsletters program writes the Zipped file into this Folder.
If Directory.Exists(myFolder) Then
myFolder = myFolder + "\Current_Season\"
If Directory.Exists(myFolder) Then
'do nothing
Else
Directory.CreateDirectory(myFolder)
End If
Else
Directory.CreateDirectory(myFolder)
myFolder = myFolder + "\Current_Season\"
Directory.CreateDirectory(myFolder)
End If
'The zipped file for this league should already exist
LeftCB = myLeague.ToString
LeftCB = LeftCB.Substring(0, 3)
myRARfile = myFolder + LeftCB + mySession + ".zip"
'Process the Zipped file
If File.Exists(myRARfile) Then
ZipTest()
Else
myErrorMsg = "ERROR - Aborting ..."
MsgBox(myErrorMsg, vbCritical)
MSWord.Quit()
Exit Sub
End If
I would hope that this particular case would never happen, but in my tests it does happen and this weird "OK has been clicked" event is happening !!!
However, there are similar messages later in the program that check for other files and they too are saying I have clicked the OK Button when I clearly haven't !!!
-
Re: MSGBOX not displaying, OK being automatically selected.
Quote:
Originally Posted by
dunfiddlin
Well there's nothing in the code that explains it. Do you have any kind of automated keypresses, clicks etc. going on either in this program or another running concurrently with it. I notice that you have a live Word application so is that possibly a source or recipient of such an event?
I don't know ... I don't think so, I did at one point try to use AutoHotKey, but I couldn't get it to work so deleted it, but even so, I don't understand how it would affect some Error Messages and not others !!!
I create the Word document in this program, that is what it's doing, I am not doing anything particularly complicated here, I am creating a Word Document, unzipping a zipped file and opening the files I want in Notepad++ & Excel ... Everything is great apart from these MsgBox problems ... that's why I am so frustrated !!!
-
2 Attachment(s)
Re: MSGBOX not displaying, OK being automatically selected.
Ok, here is me stepping through the program in Debug mode using F8 ...
Attachment 97035Attachment 97037
No MsgBox opens, it just ends the program !!!
-
Re: MSGBOX not displaying, OK being automatically selected.
Well there are a few things that I noticed right off the bat, that I personally would change. First, I would use the .net version of MsgBox which is MessageBox. You're also using the "+" sign to concate strings, use the "&" sign instead, + is for adding integers & is for concating strings. But finally I notice that you're closing the form before anything is being done. When you call Me.Close, the rest of your code will not perform. If you don't want the form to be visible when the rest of the code is being performed, call Me.Hide.
-
Re: MSGBOX not displaying, OK being automatically selected.
Even considering those points, that's some pretty bizarre behavior. MsgBox may be a legacy from VB6, but it still works the same way...I think. I guess that would be my first change. Maybe there IS some difference between the two. Other than that, I'd have to say that I've never seen anything quite like this.
-
Re: MSGBOX not displaying, OK being automatically selected.
Is there not a possibility that IntelliTrace is itself the problem? I've never used it but that in itself is significantly the only difference between your debugging and mine (which doesn't do anything like this).
-
Re: MSGBOX not displaying, OK being automatically selected.
Quote:
Originally Posted by
dday9
Well there are a few things that I noticed right off the bat, that I personally would change. First, I would use the .net version of MsgBox which is
MessageBox. You're also using the "+" sign to concate strings, use the "&" sign instead, + is for adding integers & is for concating strings. But finally I notice that you're closing the form before anything is being done. When you call
Me.Close, the rest of your code will not perform. If you don't want the form to be visible when the rest of the code is being performed, call
Me.Hide.
I will try as you say, I'm no expert, quite the opposite ... I didn't know MsgBox & MessageBox were different, and I use "&" in VBA, I thought "+" was the correct thing to use in VB.net ... different sites, different (not always correct !) help ...
I'm not sure what you mean when you say "When you call Me.Close, the rest of your code will not perform" because it clearly *does" perform, I follow it through, though I can move the Close further down the logical path, but once I have clicked on the Button to take the data from the 2 Dropdown boxes, the data is stored in Variables and the Form is finished with, I don't need to Hide it ...
-
Re: MSGBOX not displaying, OK being automatically selected.
Quote:
Originally Posted by
dunfiddlin
Is there not a possibility that IntelliTrace is itself the problem? I've never used it but that in itself is significantly the only difference between your debugging and mine (which doesn't do anything like this).
I don't know, I cannot understand this at all, which is why I am here asking for help !!!
I didn't even know what "IntelliTrace" was until I saw these messages up there ... well, I still don't really, I am a COBOL programmer just trying to learn VB.net & write fairly simple programs yet I keep running into the most absurd problems :mad: !!!
-
Re: MSGBOX not displaying, OK being automatically selected.
Quote:
Originally Posted by
dday9
First, I would use the .net version of MsgBox which is
MessageBox
I just changed all occurrences of MsgBox to MessageBox and have 13 of the longest error messages I have ever seen :eek: ... I think I will go and have my dinner, have a decent night's sleep & look again in the morning ... thanks for your hepl so far though, all of you ...
-
Re: MSGBOX not displaying, OK being automatically selected.
Quote:
Originally Posted by
vodkasoda
I just changed all occurrences of MsgBox to MessageBox and have 13 of the longest error messages I have ever seen :eek: ... I think I will go and have my dinner, have a decent night's sleep & look again in the morning ... thanks for your hepl so far though, all of you ...
Yeah, the syntax is a bit more complicated. Slightly disingenuous to say they're equivalent.
MessageBox.Show("Hello", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
-
Re: MSGBOX not displaying, OK being automatically selected.
Quote:
Slightly disingenuous to say they're equivalent
Did I say equal? I ment better than :]
-
Re: MSGBOX not displaying, OK being automatically selected.
OK, Thank you everybody, dday9 was on the right lines when he said "When you call Me.Close, the rest of your code will not perform". As I said, the code does perform, BUT this is definitely what is affecting the MessageBox display, because if I move the "Me.Close" to after all the validation checks, it works !!!
When the Form is open, the MessageBox commands always display directly on top of it, I can only assume that the Form defines the "Display Window" (for want of a better expression) for the program and if you close the Form, you close the Window and therefore the ability of the MessageBoxes to display properly !!!
If anybody can explain that and/or word it better, please do !!!
Thanks again, though, for all of your help, that has had me baffled for ages !!!
-
Re: MSGBOX not displaying, OK being automatically selected.
I think you are pretty close with your reasoning for message boxes not showing: closing the window, and subsequently showing a message box would cause the closing of the window operation to 'break'. There is probably a function within the MessageBox call which checks for a parent window to attach to, and if it doesn't exist, simply returns the default option. I haven't investigated this, but it seems reasonable.
MsgBox and MessageBox are identical. MsgBox is a wrapper function around the MessageBox function, while converting the VB6 calling signature to the standard MessageBox signature. Thus, calling the MessageBox function directly short-circuits the unnecessary overhead. Indeed, the MsgBox function exists solely to aid backwards compatibility and conversion from VB6 to .NET.
-
Re: MSGBOX not displaying, OK being automatically selected.
Thank you for that explanation, it's nice to have something explained in such clear English :-) !!!