0

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

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by pritesh2010
0

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)
0

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

0

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

Edited by pritesh2010: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.