# VB2008 Form.Close



## rhysduk (May 9, 2009)

Im in the middle, or just starting to try out the 'new' Visual Studio 2008.

I have a form, that On Loading (Form1_Load) displays a MsgBox to the user asking for input. For the life of me I can not get the form to go away if NO is clicked.
My code is as follows:


```
Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim msgresult As MsgBoxResult
        Dim msg As Long
        msg = MsgBox("Would you like to run the backup?", MsgBoxStyle.YesNo, "Backup")
        If msg = vbYes Then
            Me.Show()
            If msg = vbNo Then
                Me.Close()
            End If

        End If
    End Sub
End Class
```
I'm considering going back to VB6, much easier! Thanks guys.


----------



## pvc_ (Feb 18, 2008)

If msg = vbYes Then
Me.Show()
else
Me.Close()
End If

This really isn't VB.Net's fault. Your logic has flaws in it.


----------



## rhysduk (May 9, 2009)

pvc_ said:


> If msg = vbYes Then
> Me.Show()
> else
> Me.Close()
> ...


Sorry, but what was the point in your post? I appreciate the help I really do, but your post was pointless. Evidently it has flaws in it, as it's not working!

I've also tried:


```
If msgBoxResult = vbYes Then
```
but to no success.

Thanks.


----------



## pvc_ (Feb 18, 2008)

```
Dim MsgRes As MsgBoxResult

        MsgRes = MessageBox.Show("Would you like to run the backup?", "Backup", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        If MsgRes = MsgBoxResult.No Then
            Me.Close()
        End If
```
This works on my end. If it doesn't work for you, it might have something to do with how you have setup your startup form settings...

What was the point of my post??

In your original code you had an if statement checking to see if the result is "yes" and then if the response was yes, you were checking to see if the respose was a "No." Makes no logical sense, right? How could the response be Yes and No at the same time??


----------



## pvc_ (Feb 18, 2008)

I just noticed you were using the old msgbox() instead of messagebox.show(). Use .net's messagebox.show() instead.


----------

