Results 1 to 17 of 17

Thread: MSGBOX not displaying, OK being automatically selected.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    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

    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 , so if somebody can tell me what on earth is going on here, I'll be eternally grateful !!!

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    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.
    My usual boring signature: Nothing

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Re: MSGBOX not displaying, OK being automatically selected.

    Quote Originally Posted by Shaggy Hiker View Post
    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 !!!

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Re: MSGBOX not displaying, OK being automatically selected.

    Quote Originally Posted by dunfiddlin View Post
    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 !!!

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Re: MSGBOX not displaying, OK being automatically selected.

    Ok, here is me stepping through the program in Debug mode using F8 ...

    Name:  ScreenHunter_305 Feb. 26 22.40.jpg
Views: 12281
Size:  117.0 KBName:  ScreenHunter_305 Feb. 26 22.41.jpg
Views: 11075
Size:  140.2 KB

    No MsgBox opens, it just ends the program !!!

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    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.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    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.
    My usual boring signature: Nothing

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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).
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Re: MSGBOX not displaying, OK being automatically selected.

    Quote Originally Posted by dday9 View Post
    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 ...

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Re: MSGBOX not displaying, OK being automatically selected.

    Quote Originally Posted by dunfiddlin View Post
    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 !!!

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Re: MSGBOX not displaying, OK being automatically selected.

    Quote Originally Posted by dday9 View Post
    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 ... 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 ...

  13. #13
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: MSGBOX not displaying, OK being automatically selected.

    Quote Originally Posted by vodkasoda View Post
    I just changed all occurrences of MsgBox to MessageBox and have 13 of the longest error messages I have ever seen ... 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)
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  14. #14
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: MSGBOX not displaying, OK being automatically selected.

    Slightly disingenuous to say they're equivalent
    Did I say equal? I ment better than :]
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    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 !!!
    Last edited by vodkasoda; Feb 27th, 2013 at 02:58 AM. Reason: Spelling

  16. #16
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    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.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Re: MSGBOX not displaying, OK being automatically selected.

    Thank you for that explanation, it's nice to have something explained in such clear English :-) !!!

Tags for this Thread

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