Results 1 to 7 of 7

Thread: [RESOLVED] Using vbNo and vbYes

  1. #1

    Thread Starter
    Banned
    Join Date
    Aug 2009
    Posts
    333

    Resolved [RESOLVED] Using vbNo and vbYes

    How would I change it so that if a person clicked no, nothing happens?
    Code:
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            If (e.CloseReason = CloseReason.UserClosing) Then
                MsgBox("Are you sure?", vbYesNo + vbQuestion, "Confirm")
                If vbYes Then
                    Close()
                    If vbNo Then
                    End If
                End If
            End If
        End Sub
    End Class

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Using vbNo and vbYes

    You know MsgBox is a function right?

  3. #3

    Thread Starter
    Banned
    Join Date
    Aug 2009
    Posts
    333

    Re: Using vbNo and vbYes

    Quote Originally Posted by ForumAccount View Post
    You know MsgBox is a function right?
    But how do I make it not close?

  4. #4

    Re: Using vbNo and vbYes

    Why would you want to make it not close? That's kind of the point of the Msgbox, to make a message appear and you close it.

  5. #5
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Using vbNo and vbYes

    if you mean how to stop the form from closing....

    Code:
    if vbNo then
      e.Cancel  = True
    endif
    however you really need to take a close look at your logic.....

    vb Code:
    1. If vbYes Then
    2.                 Close()
    3.                 If vbNo Then
    4.                 End If
    5.             End If
    using that code, the check for vbNo will no be done if No is selected.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  6. #6

    Re: [RESOLVED] Using vbNo and vbYes

    First, Msgbox() is not the proper format you'd use to do this. You would use Messagebox.show(), which has more power and manipulation than Msgbox(), which is just a wrapper.

    Messagebox.show() is what you'd like to use to control YesNo operations, don't use old legacy vb code in a vb.net application.

  7. #7
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: [RESOLVED] Using vbNo and vbYes

    To sum up what the others are saying with an example:

    Code:
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            If (e.CloseReason = CloseReason.UserClosing) Then
                If MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
                    e.Cancel = True
                End If
            End If
        End Sub
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

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