Log out form

Manesti

Member
Joined
Jan 16, 2009
Messages
16
Programming Experience
Beginner
I have 2 forms in my project. I want a case where by a user can click a log out button and the main form is disabled while, the login form shows. But if I try to log in again and enable the main form, this does not work.

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim login As New Login
        ' Me.Enabled = False   'disables the main form
        login.ShowDialog()

        Label18.Text = ""

    End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim userlevel As String

        'log in using name and password
        If txtuser.Text = "" Or txtpass.Text = "" Then
            MsgBox("Enter Full Log in Details")
            Return
        End If

        userlevel = UserLogIn(txtuser.Text, txtpass.Text)
        counter = userLogCount()

        If userlevel <> "" Then


            If counter > 1 Then
                Me.Hide()
                main.Enabled = True

                Exit Sub
            End If

            Me.Hide()

            'check user privilege and disable features 
            If userlevel = "regular" Then

                main.Label58.Enabled = False
                main.Label9.Enabled = False
                main.Label10.Enabled = False
                main.Label4.Enabled = False
                main.Label55.Enabled = False

            End If

            main.Show()


        Else

            'wrong password
            MessageBox.Show("Wrong User Name or Password, Contact Admin.", "Log In", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
            counter = counter + 1
            txtuser.Text = ""
            txtpass.Text = ""
        End If
        logcount(counter)

    End Sub

    Private Sub logcount(ByVal number As Integer)
        If number >= 3 Then
            MsgBox("Maximum Try, Contact Admin")
            Me.Close()
        End If

    End Sub
 
What do you mean it doesn't work? You get an error.... The main form doesn't show.... The login form doesn't show..... ????
 
When I click the log out button, the main form is disabled, and the login form shows. but when I try to log in and enable the main form, that dos nt work
 
exactl, its doing doing What I expect it to do. As in, hide the log out form and make he main form enabled.
 
if I understand correctly, I think the issue is in here:

VB.NET:
 If counter > 1 Then
                Me.Hide()
                main.Enabled = True

                Exit Sub
            End If

this looks like it is saying
If the user count is more than 1, then hide the login form, and enable the main form then skip over the setting of privileges and features. Possibly this should not enable the main form?
 
Correct, That is where the issue is. If a user clicks the login button the counter is incremented. If the counter is > 1, then the log out hides and the main form is enabled. But it doesnt get enabled(thats the problem) Thnk you.
 
How and where is the variable "main" declared? I am thinking that this is not referencing the form that you think it is.
 
Think I know what it is.

You are showing the login form with
VB.NET:
login.ShowDialog()
this tells the main form to wait until the login form is closed and a result is returned. You will need to change the code to

VB.NET:
login.Show()

or in the login form you can return a DialogResult and then handle the enabling or disabling on the main form.
 
well, I did not how that part. Its the form.
dim main as new MiainForm.

It is because the when I do main.showitdisplays the main form
 
Back
Top