CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2010
    Posts
    3

    Unhappy Need help about variables

    Firstly I'm new to vb6 and I'm using it in a 'o' level project.
    I would like that the new password i entered is save permanently because once i close the form the password re-becomes: Bringback , again.
    Hope you understand.
    The code is in the attachement.
    Attached Images Attached Images  

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Need help about variables

    You would need to save the password either to a file, a database or the registry.
    You would also need to read this password from whichever source you are using at startup.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Apr 2010
    Posts
    3

    Re: Need help about variables

    Is there a way to include it in the form itself by the use of codes?

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Need help about variables

    Nope, unless you want to hardcode your passwords - which is not ( absolutely ot ) a good idea, plus, you want differing passwords, so the best option would be to follow DataMiser's advice.

  5. #5
    Join Date
    Apr 2010
    Posts
    3

    Re: Need help about variables

    OK Thanks everybody.

  6. #6
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Smile Re: Need help about variables

    Firstly I'm new to vb6 and I'm using it in a 'o' level project.
    I would like that the new password i entered is save permanently because once i close the form the password re-becomes: Bringback , again.
    Hope you understand.
    The code is in the attachement.
    this might be a Great help for you .Just write the password in the tag property of form.you can change the password store in tag.according to your need.
    Code:
    Option Explicit
    
    Public LoginSucceeded As Boolean
    
    Private Sub cmdCancel_Click()
        LoginSucceeded = False
        Me.Hide
    End Sub
    
    Private Sub cmdOK_Click()
        'check for correct password
        If txtPassword = frmLogin.Tag Then
            'place code to here to pass the
            'success to the calling sub
            'setting a global var is the easiest
            LoginSucceeded = True
            FrmDataentry.Show 'Whatever you want after login!!!!!!!!!!!!!!!!!!!!
            Me.Hide
        Else
            MsgBox "Invalid Password, try again!", , "Login"
            txtPassword.SetFocus
            SendKeys "{Home}+{End}"
        End If
    End Sub

  7. #7
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Need help about variables

    That won't help. Like everything else in the program it will reset when the program is started again. You must use a method of saving the data for it to persist the next time you run the program.
    Always use [code][/code] tags when posting code.

  8. #8
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Need help about variables

    Quote Originally Posted by firoz.raj View Post
    this might be a Great help for you .Just write the password in the tag property of form.you can change the password store in tag.according to your need.
    Dont follow this 'great help'. When you start the program the tag property is always empty. So this will not work in no case. Only if you have a built in password which is hardcoded that way.Anyone using an editor is able to read out that password by simple looking into the exe file then.
    What you can do is writing to registry and reading from registry
    Writing to registry is done like
    Code:
    Call SaveSetting(app.EXEName , "Setup", "Password", txtPassword.Text)
    txtPassword is the textbox where you are setting your password, for example you may have a form which allows you to store different varables used for the program and there you decide to choose a Password for that person.
    To retrieve that data you can use the following code
    Code:
    Dim sPassword as string
    sPassword = GetSetting(app.EXEName , "Setup", "Password","")
    This you may compare with the users input and then decide if he is allowed for using your program
    Last edited by JonnyPoet; April 27th, 2010 at 03:13 AM.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  9. #9
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Need help about variables

    Quote Originally Posted by Lightsmage View Post
    Is there a way to include it in the form itself by the use of codes?
    Yes, as I said before you must save it to a file, a database or a registry. The EXE that will be generated by your program is a file and you can save data to it though I would not suggest this for a beginer it is possible.

    That said you still need to write code to save the new password to a file and you will need to write code to read the password at program startup. Otherwise the password will always revert to whatever it was set to the first time you ran the program each time you start the exe.
    Always use [code][/code] tags when posting code.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured