| Mirage Source http://web.miragesource.net/forums/ |
|
| Remember password & username http://web.miragesource.net/forums/viewtopic.php?f=210&t=1433 |
Page 1 of 1 |
| Author: | Braydok [ Sat Mar 03, 2007 12:36 pm ] |
| Post subject: | Remember password & username |
Difficultly: 1/5 Time: Three minutes Hello, I am completely new here, but I know my way around VB6 a little, so I worked up a code that remembers your username and password if you check a button. Here goes: OK, first open up your frmLogin and add a check box and call it RPass. Then double click on the connect button and add this code to the top, right under the Private sub picConnect_click(): Code: If RPass.Value = 1 Then Open "Data.ini" For Output As #f Print #f, "[SETTINGS]" Print #f, "Last User= " Print #f, txtName Print #f, "Last Password= " Print #f, txtPassword Close #f Else End If Then add this into the form_load() Code: f = FreeFile Dim n Dim O Dim usr Dim t Dim pass On Error GoTo Error Open "Data.ini" For Input As #f Input #f, n Input #f, O Input #f, usr Input #f, t Input #f, pass Close #f RPass.Value = 1 txtName.Text = usr txtPassword.Text = pass Error: Then up at the top, write this in: Code: public f as Integer
That works for me. Just make sure to keep the Trim part of the code there. That should do it, but you might have to create a file called data.ini, because it might runtime. ~Braydok |
|
| Author: | William [ Sat Mar 03, 2007 12:43 pm ] |
| Post subject: | |
It's nice to see that you are trying to share your code. Although there are a few things thats wrong. I suggest you test it before sharing it |
|
| Author: | Lea [ Sat Mar 03, 2007 2:24 pm ] |
| Post subject: | |
You dont want to specify the number yourself. If that number is already open elsewhere, you can cause problems. What you do is do Dim f as integer F = freefile Open "Data.ini" for output as #f Also, Data.ini should have the entire path, so do App.Path & "\Data.ini" Also, for the INI files there are special functions that edit the values directly, without rewriting the file. They're called GetVar and PutVar. |
|
| Author: | Robin [ Sat Mar 03, 2007 5:44 pm ] |
| Post subject: | |
My votes winning! |
|
| Author: | Braydok [ Sun Mar 04, 2007 6:18 pm ] |
| Post subject: | |
William wrote: It's nice to see that you are trying to share your code. Although there are a few things thats wrong. I suggest you test it before sharing it
Shoot you, I did test it, did you think I would not test it? |
|
| Author: | William [ Sun Mar 04, 2007 6:22 pm ] |
| Post subject: | |
Bah, the code you supplied will only save it. Not load it into the text boxes. |
|
| Author: | Robin [ Sun Mar 04, 2007 6:57 pm ] |
| Post subject: | |
Braydok wrote: William wrote: It's nice to see that you are trying to share your code. Although there are a few things thats wrong. I suggest you test it before sharing it Shoot you, I did test it, did you think I would not test it? Yes. We obviously think you didn't test it because it doesn't work. |
|
| Author: | Braydok [ Sun Mar 04, 2007 8:48 pm ] |
| Post subject: | |
Shit, your right, forgive me, here is the full code: In the sub connect_click() Code: Private Sub picConnect_Click() If RPass.Value = 1 Then Open "Data.ini" For Output As #f Print #f, "[SETTINGS]" Print #f, "Last User= " Print #f, txtName Print #f, "Last Password= " Print #f, txtPassword Close #f Else End If Then add this into the form_load() Code: f = FreeFile Dim n Dim O Dim usr Dim t Dim pass On Error GoTo Error Open "Data.ini" For Input As #f Input #f, n Input #f, O Input #f, usr Input #f, t Input #f, pass Close #f RPass.Value = 1 txtName.Text = usr txtPassword.Text = pass Error: Then up at the top, write this in: Code: public f as Integer
That works for me. Is this code good? |
|
| Author: | Lea [ Sun Mar 04, 2007 11:22 pm ] |
| Post subject: | |
It's still pointlessly complex. Code: Private Sub picConnect_Click() If RPass.Value = 1 Then PutVar(App.Path & "\Data.ini", "Settings", "LastUser", Trim$(txtNAme.text) PutVar(App.Path & "\Data.ini", "Settings", "LastPassword", Trim$(txtPassworld.text) Else Call PutVar(App.Path & "\Data.ini", "Settings", "LastUser", VBNullString) Call PutVar(App.Path & "\Data.ini", "Settings", "LastPassword", vbNullString) End If In Form_Load Code: txtName.Text = GetVar(App.Path & "\Data.ini", "Settings", "LastUser")
txtPassword.Text = GetVar(App.Path & "\Data.ini", "Settings", If txtName.text <> vbNullstring Then RPass.value = 1 "LastPassword") |
|
| Author: | Braydok [ Sun Mar 04, 2007 11:29 pm ] |
| Post subject: | |
Uh, yeah, I am still new at VB6, just started getting into it one week ago, so I don't know all the PutVar and stuff, so I'll work on that, thanks. ~Braydok |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|