1 Attachment(s)
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.
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.
Re: Need help about variables
Is there a way to include it in the form itself by the use of codes?
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.
Re: Need help about variables
Re: Need help about variables
Quote:
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
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.
Re: Need help about variables
Quote:
Originally Posted by
firoz.raj
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'. :rolleyes: 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
Re: Need help about variables
Quote:
Originally Posted by
Lightsmage
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.