hi every 1. i am trying to make a logout message box where it says "Are you sure you want to logout" and the options are yes or No. If user clicks Yes it should logout and its hould show login screen and if user clicks No. It should show the same form or the option remains un changed. below is my code. The problem is even if i click No. it logs out and takes me to login screen.

Dim result As String
MsgBox("Are You Sure You Want To Logout", MsgBoxStyle.YesNo, MsgBoxResult.Yes)
result = MsgBoxResult.Yes
If result = MsgBoxResult.Yes Then
login.txtUserName.Clear()
login.txtPassword.Clear()
Me.Hide()
login.Show()
ElseIf result= MsgBoxResult.No Then
Me.Show()
End If
End Sub

You are setting result to 'Yes' which of course means the 'else' part of your if statement never gets called. Try:

result = MsgBox("Are You Sure You Want To Logout", MsgBoxStyle.YesNo, MsgBoxResult.Yes)

hello !
use this code

If MsgBox("r u sure ", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
            'your form closing code
        End If

Hope this will help you ,if yes please vote me up :)

Regards

hi
just try this code it solve your problem

Dim result As DialogResult
        result = MessageBox.Show("r u sure", "Test", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
        If result = Windows.Forms.DialogResult.Yes Then
            //statement
        Else
//statement
        End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.