How to clear variable value after logout?

  • (2 Pages)
  • +
  • 1
  • 2

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

#1 chdboy  Icon User is offline

  • D.I.C Head

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

How to clear variable value after logout?

Posted 11 January 2013 - 08:11 AM

I have declared a variable in module so that I can use it whenever I needed in my program,in that variable I have stored a username ,so that any user who is logged in can change the password (nobody else)

CODE:
Module Module1
    Public u As String
End Module


and I have used this variable in this code like this to hold the username

CODE:
      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")
            


Now how can I flush the variable value after logout?

I have used
u= ""
but it didn't work

Is This A Good Question/Topic? 0
  • +

Replies To: How to clear variable value after logout?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: How to clear variable value after logout?

Posted 11 January 2013 - 08:16 AM

What do you mean

u= ""


didn't work?
Was This Post Helpful? 0
  • +
  • -

#3 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 11 January 2013 - 08:29 AM

after I logout and still my application is running ,after that I again click login ,and then forget password the username is still there from the last session
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: How to clear variable value after logout?

Posted 11 January 2013 - 08:34 AM

So what.. you are not clearing out the textboxes?

TextBox1.Tex = string.empty

Was This Post Helpful? 0
  • +
  • -

#5 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 11 January 2013 - 08:36 AM

And here is the code where I used the variable in Recover password form

CODE:
Private Sub Recoverpass_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'add items to combo
        txtuname.ReadOnly = True
        Me.txtuname.Text = (u)
End Sub


If I'm not mistaken I have used this code in wrong handle
now the question is where should I have used that?
Every time I click on recover password/forget password
and the Recoverpass_form loads then it takes the old session username which is stored in variable 'u'
but I'm not sure that,that is the problem
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: How to clear variable value after logout?

Posted 11 January 2013 - 08:50 AM

I can't make an assessment on the little amount of code you provided. At best I can tell you - slap a break point and track the variable.

The easiest should be in the 'sign out button click event' set all your textboxes and variables to 'string.empty'.
Was This Post Helpful? 0
  • +
  • -

#7 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 11 January 2013 - 08:56 AM

Here is 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
                f.Close()
            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

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: How to clear variable value after logout?

Posted 11 January 2013 - 09:02 AM

Okay so why are you not clearing out your textfields and variables there?
Was This Post Helpful? 0
  • +
  • -

#9 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 11 January 2013 - 09:08 AM

Like I said I have tried

u = ""
but didn't worked
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,155
  • Joined: 12-June 08

Re: How to clear variable value after logout?

Posted 11 January 2013 - 09:12 AM

Yeah.. why are you not clearing out the text boxes? Have you tried putting a break point in your 'log out' code and tracking the value of "u" (by the way - horrible name for a variable)?
Was This Post Helpful? 0
  • +
  • -

#11 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 57
  • View blog
  • Posts: 288
  • Joined: 22-August 11

Re: How to clear variable value after logout?

Posted 11 January 2013 - 01:42 PM

View Postchdboy, on 11 January 2013 - 12:08 PM, said:

Like I said I have tried

u = ""
but didn't worked

It did work. It cleared out the value it was getting from your textbox but your doesn't clear the textboxes out.
So when you open it back up, there is already TEXT in the TEXTBOX, because you only cleared the variable and not the TEXTBOX.

This is what Modi is trying to say.

textbox1.text = string.empty
textbox2.text = string.empty
testbox3.text = string.empty



PS You're not paying for variable names by the characters. Do yourself, and those that follow, a favor and use meaningful variable names.
Was This Post Helpful? 0
  • +
  • -

#12 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 - 05:55 AM

here is my code after the alteration
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
                f.Close()
                u = ""
                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

but it didn't work either
the value is still there.

And my variable name is horrible because this is in the test stage ,I was learning to store a value into a variable ,I will certainly change the variable name :) .
Was This Post Helpful? 0
  • +
  • -

#13 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 57
  • View blog
  • Posts: 288
  • Joined: 22-August 11

Re: How to clear variable value after logout?

Posted 18 January 2013 - 06:57 AM

View Postchdboy, on 18 January 2013 - 07:55 AM, said:

here is my code after the alteration
Spoiler


Quote

but it didn't work either
the value is still there.


In your designer form, is there something typed into the textbox already?
Also, why do you use a loop in your if statement?
Was This Post Helpful? 0
  • +
  • -

#14 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 - 07:10 AM

Yes in my recoverpass form there is a variable stored(u) in the textbox (txtuname)and I use Loop to check weather any form is open or not ...if so close all (f)
Was This Post Helpful? 0
  • +
  • -

#15 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 57
  • View blog
  • Posts: 288
  • Joined: 22-August 11

Re: How to clear variable value after logout?

Posted 18 January 2013 - 07:33 AM

View Postchdboy, on 18 January 2013 - 09:10 AM, said:

I use Loop to check weather any form is open or not ...if so close all (f)

Ah, I see.

Wait, originally you say when you log out, but your talking code seems to be about a recover password form.

Is it the main log in form that's saving the username?

This post has been edited by torind_2000: 18 January 2013 - 07:36 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2