Results 1 to 11 of 11

Thread: [RESOLVED] Problem with MsgBoxStyle.YesNo

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    4

    Resolved [RESOLVED] Problem with MsgBoxStyle.YesNo

    Hello all,

    I've problem with this code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load



    If Not File.Exists("C:\Windows\System32\dsquery.exe") Then
    MsgBox("Do you want install Remote Server Administration Tools?", MsgBoxStyle.Question + MsgBoxStyle.YesNo)
    ElseIf MsgBoxResult.Yes Then
    System.Diagnostics.Process.Start("http://http://www.microsoft.com/download/en/details.aspx?id=7887")

    ElseIf MsgBoxResult.No Then
    Exit Sub
    End If

    The problem is:
    I want to if the user doesn't install RSAT or package dsquery.exe Clicking on the message to him referring to the page url and if it clicks in MsgBox not to stop loading the form.
    I'm sorry but I am a beginner.

    Thanks for the advice

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with MsgBoxStyle.YesNo

    You are displaying a message box but you are not actually getting the user's response. In pseudo-code, here is what you are currently doing:
    Code:
    If file does not exist
        Display message
    Otherwise if MsgBoxResult.Yes is true
        Start new process
    Otherwise if MsgBoxResult.No is true
        Exit sub
    Now, how can either MsgBoxResult.Yes or MsgBoxResult.No ever be true? neither of them is a Boolean. What you should be doing is displaying the message if the file doesn't exist and retianing the result, then testing that result to determine whether it is Yes or No:
    Code:
    If file does not exist
        Display message
        If user response is MsgBoxResult.Yes
            Start new process
        Otherwise
            Exit sub
    Also, you really should be using MessageBox.Show rather than MsgBox.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    4

    Re: Problem with MsgBoxStyle.YesNo

    Quote Originally Posted by jmcilhinney View Post
    You are displaying a message box but you are not actually getting the user's response. In pseudo-code, here is what you are currently doing:
    Code:
    If file does not exist
        Display message
    Otherwise if MsgBoxResult.Yes is true
        Start new process
    Otherwise if MsgBoxResult.No is true
        Exit sub
    Now, how can either MsgBoxResult.Yes or MsgBoxResult.No ever be true? neither of them is a Boolean. What you should be doing is displaying the message if the file doesn't exist and retianing the result, then testing that result to determine whether it is Yes or No:
    Code:
    If file does not exist
        Display message
        If user response is MsgBoxResult.Yes
            Start new process
        Otherwise
            Exit sub
    Also, you really should be using MessageBox.Show rather than MsgBox.
    Thank you for your quick reply. The structure should look like this:
    If the file does not exist -> MsgBox with buttons yes or no. If the user selects Yes -> open url. If the user chooses no -> stop loading the form.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with MsgBoxStyle.YesNo

    That's exactly what I said, so now you just have to write code to do that. Remember, MsgBox (and MessageBox.Show too) is just a function, like any other. How would you usually get the value returned by a function and check its value? Here's a hint: you're already doing it with File.Exists.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Member
    Join Date
    Dec 2010
    Posts
    50

    Re: Problem with MsgBoxStyle.YesNo

    which part not stop loading?
    if msgbox=yes, the proccess will bring you to the website,
    the form will still load
    if msgbox=no
    exit sub, (means exit the form)
    is your qusetion means, when you choose no, the form still loading.
    if that is your question
    try to use
    me.close <<< to close the form when you want to

  6. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Problem with MsgBoxStyle.YesNo

    Actually what he should be doing is use the Application Startup event and if the file exists or the user selects "no" from the MessageBox.Show() then load the form. If they select "yes" From the MessageBox.Show() then Process.Start() the URL and don't load the form.

    If you call 'Me.Close()' in the app's main load form, that's a huge indication you should probably use the Startup event and not have the program load most of the form just to cancel loading it.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with MsgBoxStyle.YesNo

    Ah, I didn't pick up the bit about not loading the form. Even re-reading the post it's not too clear, which is presumably a language issue. If you're not a native English speaker then all is forgiven. If you are a native English speaker then you should work on posting a bit more clearly.

    Anyway, what I posted before still stands as far as the structure of the code goes. JB is correct that the code should go in the Startup event handler of the application if you may want to not actually display the main form. You can access application events from the Application page of the project properties. To have the application exit without ever creating and displaying the main form, set e.Cancel to True.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Lively Member
    Join Date
    Oct 2011
    Posts
    121

    Re: Problem with MsgBoxStyle.YesNo

    is this what you mean?
    Code:
    If filedoesntexit() Then
    
    If msgbox("your text here that you will display on the message box", msgboxstyle.question + msgboxstyle.yesno).show() = windows.forms.dialogresult.Yes Then
    
    'your code here when the user clicks yes
    
    else
    
    'your code here for when the user clicks no
    
    end if
    
    End If

  9. #9

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    4

    Re: Problem with MsgBoxStyle.YesNo

    Quote Originally Posted by jmcilhinney View Post
    Ah, I didn't pick up the bit about not loading the form. Even re-reading the post it's not too clear, which is presumably a language issue. If you're not a native English speaker then all is forgiven. If you are a native English speaker then you should work on posting a bit more clearly.

    Anyway, what I posted before still stands as far as the structure of the code goes. JB is correct that the code should go in the Startup event handler of the application if you may want to not actually display the main form. You can access application events from the Application page of the project properties. To have the application exit without ever creating and displaying the main form, set e.Cancel to True.
    O sorry I'm not native speaker .
    Once more:
    I want to verify when loading applications if exist file in %SystemRoot%\Dsquery.exe . After If file not found, will be loaded msgbox with following message: "Do you want install RSAT?". If user clicks on yes, then open web page e.g. www.google.cz. If user clicks no , then stop loading aplication. Do you understand me?

    Regards
    V.

  10. #10

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    4

    Re: Problem with MsgBoxStyle.YesNo

    Quote Originally Posted by rqmok View Post
    is this what you mean?
    Code:
    If filedoesntexit() Then
    
    If msgbox("your text here that you will display on the message box", msgboxstyle.question + msgboxstyle.yesno).show() = windows.forms.dialogresult.Yes Then
    
    'your code here when the user clicks yes
    
    else
    
    'your code here for when the user clicks no
    
    end if
    
    End If
    Yes yes yes. U're great. It works! Thx very much

  11. #11
    Lively Member
    Join Date
    Oct 2011
    Posts
    121

    Re: [RESOLVED] Problem with MsgBoxStyle.YesNo

    You know you're the first one I helped out!

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