How to clear variable value after logout?

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 1927 Views - Last Post: 03 February 2013 - 08:38 PM Rate Topic: -----

#16 chdboy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 26-July 12

Re: How to clear variable value after logout?

Posted 18 January 2013 - 08:07 AM

It is the form where I have stored the username(Current user logged in) who can change the password (Only user logged in )using password recovery form (recoverpass)so in my recoverpass lies the field(txtuname) which holds the (u) username ,that is the field I wanted to make empty when logged out

This post has been edited by chdboy: 18 January 2013 - 08:07 AM

Was This Post Helpful? 0
  • +
  • -

#17 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 55
  • View blog
  • Posts: 282
  • Joined: 22-August 11

Re: How to clear variable value after logout?

Posted 18 January 2013 - 01:56 PM

I'd really like to see the code of your login form, not the recoverpass form.
Was This Post Helpful? 0
  • +
  • -

#18 chdboy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 26-July 12

Re: How to clear variable value after logout?

Posted 18 January 2013 - 10:22 PM

Please see my #1 post in this thread .
Was This Post Helpful? 0
  • +
  • -

#19 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: How to clear variable value after logout?

Posted 19 January 2013 - 11:23 AM

View Postchdboy, on 18 January 2013 - 11:22 PM, said:

Please see my #1 post in this thread .

That post contains only a few snippets that are not shown in context. If you expect anyone to actually provide help, you need to pay attention to what is being asked of you, and you also need to pay attention to the advice that's being given.

torind_2000 asked you for the code for the login form, and you have not supplied it.

You were advised to clear out the TextBox that supplies the user name when you log out, yet in your post #7 in this thread, in which you post the code of your logout button, there is no code to clear out u or TextBox1.Text.

None of the volunteers here are very good at reading your mind, so you have to follow advice and follow directions if you want help.

This post has been edited by lar3ry: 19 January 2013 - 11:23 AM

Was This Post Helpful? 0
  • +
  • -

#20 chdboy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 26-July 12

Re: How to clear variable value after logout?

Posted 22 January 2013 - 09:40 AM

Here is the code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Mainfrm.mnuLlogout.Enabled = True
        'LinkLabel2.Enabled = True
        If (TextBox1.Text.Trim = "") Then
            MessageBox.Show("PLEASE DO NOT USE BLANK SPACES", "Data Entry Error")

        ElseIf (TextBox2.Text.Trim = "") Then
            MessageBox.Show("PLEASE DO NOT USE BLANK SPACES", "Data Entry Error")


        Else     'if user has not entered a blank space 
            con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Danial\documents\visual studio 2010\Projects\ESI_PF_Payroll_V1\ESI_PF_Payroll_V1\Pay.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "SELECT * FROM tbllogin where username = '" & TextBox1.Text & "'  and password = '" & TextBox2.Text & "';"
            u = TextBox1.Text
            cmd.Connection = con
            adaptor.SelectCommand = cmd
            adaptor.Fill(dataset, "O")
            Dim count = dataset.Tables(0).Rows.Count
            If count > 0 Then
                MessageBox.Show("Welcome to the program!")
                Mainfrm.mnuLlogin.Enabled = False
                Mainfrm.mnuLchangepass.Enabled = True
                Mainfrm.MmEmplmaster.Enabled = True
                Mainfrm.MmEmpmaster.Enabled = True
                Mainfrm.Mmforms.Enabled = True
                Mainfrm.Mmwindows.Enabled = True
                Me.Hide()
                
                con.Close()
            Else
                MsgBox("INCORRECT USERNAME OR PASSWORD", MsgBoxStyle.Critical)
                TextBox1.Clear()
                TextBox2.Clear()
                TextBox1.Focus()
                con.Close()
            End If
        End If

    End Sub

Was This Post Helpful? 0
  • +
  • -

#21 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: How to clear variable value after logout?

Posted 22 January 2013 - 09:56 AM

Have you tried putting

U = String.Empty right before the f.close() in your logout code?

In other words you ask if the user want to log out. When they click yes, you close the form but prior to closing the form, set u = String.Empty or u = "" or any other equivalent of setting a string to empty.

Also, in your login code, why are you even setting U = TextBox1.Text before you even check to see if the login was successful? I would think that only upon a successful login would you store the user into your public u variable.
Was This Post Helpful? 0
  • +
  • -

#22 chdboy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 26-July 12

Re: How to clear variable value after logout?

Posted 23 January 2013 - 05:02 AM

Login Page code ,some changes I have made


 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Mainfrm.mnuLlogout.Enabled = True
        'LinkLabel2.Enabled = True
        If (TextBox1.Text.Trim = "") Then
            MessageBox.Show("PLEASE DO NOT USE BLANK SPACES", "Data Entry Error")

        ElseIf (TextBox2.Text.Trim = "") Then
            MessageBox.Show("PLEASE DO NOT USE BLANK SPACES", "Data Entry Error")


        Else     'if user has not entered a blank space 
            con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Danial\documents\visual studio 2010\Projects\ESI_PF_Payroll_V1\ESI_PF_Payroll_V1\Pay.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "SELECT * FROM tbllogin where username = '" & TextBox1.Text & "'  and password = '" & TextBox2.Text & "';"
            'u = TextBox1.Text(I have changed this line)
            cmd.Connection = con
            adaptor.SelectCommand = cmd
            adaptor.Fill(dataset, "O")
            Dim count = dataset.Tables(0).Rows.Count
            If count > 0 Then
                u = TextBox1.Text'( and I have inserted line here)
                MessageBox.Show("Welcome to the program!")
                Mainfrm.mnuLlogin.Enabled = False
                Mainfrm.mnuLchangepass.Enabled = True
                Mainfrm.MmEmplmaster.Enabled = True
                Mainfrm.MmEmpmaster.Enabled = True
                Mainfrm.Mmforms.Enabled = True
                Mainfrm.Mmwindows.Enabled = True
                Me.Hide()

                con.Close()
            Else
                MsgBox("INCORRECT USERNAME OR PASSWORD", MsgBoxStyle.Critical)
                TextBox1.Clear()
                TextBox2.Clear()
                TextBox1.Focus()
                con.Close()
            End If
        End If

    End Sub


and my logout button code

 Private Sub LogOutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuLlogout.Click
        ' Declare a Form object and call the Close event
        Dim f As Form
        For Each f In Me.MdiChildren
            If MessageBox.Show("Do you want to Logout?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult = vbYes Then
                u = ""
                u = String.Empty
                f.Close()
                
                Recoverpass.txtuname.Text = String.Empty
            Else
                If DialogResult = vbNo Then

                    Exit Sub
                End If
            End If

        Next
        mnuLchangepass.Enabled = False
        mnuLlogout.Enabled = False
        mnuLlogin.Enabled = True
        MmEmplmaster.Enabled = False
        MmEmpmaster.Enabled = False
        Mmforms.Enabled = False
        Mmwindows.Enabled = False

    End Sub


As you can see I have used two line that you provided.

But the username from earlier login is still there in the recoverpass form.
Was This Post Helpful? 0
  • +
  • -

#23 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: How to clear variable value after logout?

Posted 23 January 2013 - 05:22 AM

instead of f.close() put f.Dispose()

I've had trouble with some MDI forms that don't seem to dispose after a close. See if that clears the field.
Was This Post Helpful? 0
  • +
  • -

#24 chdboy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 26-July 12

Re: How to clear variable value after logout?

Posted 23 January 2013 - 07:22 AM

f.Dispose()


It also does not work.
Was This Post Helpful? 0
  • +
  • -

#25 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: How to clear variable value after logout?

Posted 23 January 2013 - 10:08 AM

Quote

But the username from earlier login is still there in the recoverpass form.


 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'..........
        Else     'if user has not entered a blank space 
            con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Danial\documents\visual studio 2010\Projects\ESI_PF_Payroll_V1\ESI_PF_Payroll_V1\Pay.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "SELECT * FROM tbllogin where username = '" & TextBox1.Text & "'  and password = '" & TextBox2.Text & "';"
'......
    End Sub



 Private Sub LogOutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuLlogout.Click
        ' Declare a Form object and call the Close event
        Dim f As Form
        For Each f In Me.MdiChildren
            If MessageBox.Show("Do you want to Logout?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult = vbYes Then
                u = ""
                u = String.Empty
                f.Close()
                
                Recoverpass.txtuname.Text = String.Empty
            Else
                If DialogResult = vbNo Then

                    Exit Sub
                End If
            End If

        Next
        mnuLchangepass.Enabled = False
        mnuLlogout.Enabled = False
        mnuLlogin.Enabled = True
        MmEmplmaster.Enabled = False
        MmEmpmaster.Enabled = False
        Mmforms.Enabled = False
        Mmwindows.Enabled = False

    End Sub

Let's try it this way.
Where, in the second code example (logout), do you clear TextBox1.Text?
Because, in your first code example, you check to see if TextBox1.Text is blank, and if it isn't, you use its contents.
Inquiring minds want to know.
Was This Post Helpful? 0
  • +
  • -

#26 chdboy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 26-July 12

Re: How to clear variable value after logout?

Posted 03 February 2013 - 08:38 PM

here is the code ...Just checking if the textboxes are blank or not.

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Mainfrm.mnuLlogout.Enabled = True
        'LinkLabel2.Enabled = True
        If (TextBox1.Text.Trim = "") Then
            MessageBox.Show("PLEASE DO NOT USE BLANK SPACES", "Data Entry Error")

        ElseIf (TextBox2.Text.Trim = "") Then
            MessageBox.Show("PLEASE DO NOT USE BLANK SPACES", "Data Entry Error")


        Else     'if user has not entered a blank space 
            con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Danial\documents\visual studio 2010\Projects\ESI_PF_Payroll_V1\ESI_PF_Payroll_V1\Pay.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "SELECT * FROM tbllogin where username = '" & TextBox1.Text & "'  and password = '" & TextBox2.Text & "';"
            'u = TextBox1.Text
            cmd.Connection = con
            adaptor.SelectCommand = cmd
            adaptor.Fill(dataset, "O")
            Dim count = dataset.Tables(0).Rows.Count
            If count > 0 Then
                u = TextBox1.Text
                MessageBox.Show("Welcome to the program!")

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2