Hi, am working on my assignment, i wanted to know whether there could be a way in which if i click on sign in on my vb.net button, i could get a pop up or a dialog style message asking me for the username and password. Is there any way or any possibility of carrying out such kind of technique. Please help me with info on how to do it and the codes. Thanks.

6 Years
Discussion Span
Last Post by Oxiegen

Yes, there is.
This is a quick sample of how to accomplish that.

This is the button click.

Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
   Dim login As LoginReturnCodes
   Dim lif As New LoginForm()
   If lif.ShowDialog() = DialogResult.OK Then
      login = lif.Success
   End If

   If login = LoginReturnCodes.Success Then
      'Do some coding for successful login
   ElseIf login = LoginReturnCodes.Failure Then
      MessageBox.Show("Login failed. Please try again.")
      'Do nothing
   End If
End Sub

Assuming that you already have a form in place for username and password, with a Login button and a Cancel button.
For the form, set the property AcceptButton to the Login button, and the property CancelButton to your Cancel button.
This is code for the login form.

Public Enum LoginReturnCodes
   Success = 0
   Failure = 1
End Enum

Public Class LoginForm
   Private _success As LoginReturnCodes

   Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
      'Do some checking if username and password are valid
      'If valid, set _success to LoginReturnCodes.Success
      'If not valid, set _success to LoginReturnCodes.Failure

   End Sub

   Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
   End Sub

   Public ReadOnly Property Success() As LoginReturnCodes
         Return _success
      End Get
   End Property
End Class

hi its giving me an error : LoginReturnCode not defined what should i do


On what line is the error thrown?
Did you add the Public Enum outside the class definition?


*accidental double post*

Hey its ok thanks, it worked i was just making a spelling mistake, sorry and thankyou

This question has already been answered. 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.