|
-
Mar 19th, 2011, 03:20 PM
#1
Thread Starter
Junior Member
[RESOLVED] Register/login System
How would I make it so that the contents of the form are saved and they can be used to log into the application.
Can you make it so that there is more than one account?
-
Mar 19th, 2011, 03:26 PM
#2
Re: Register/login System
If you are talking about saving stuff from application session to application session, i.e., after your app closes and then get info next time app is used, you have several options and here are some of them:
1. Use a file to store the whatever contents you want saved. Maybe an INI file
2. Use the registry to store the information
3. Use a database
If you are talking about passing information from one form to another then
1. Any form's controls can be referenced from other forms. From Form2: Me.Caption = Form1.Text1.Text
2. You can use public variables placed in a module. Public variables in a module are accessible to everything in your project
3. You can use public variables within the form that are accessed same way as controls
4. You can build public functions, sub and properties within a form
More details would be helpful depending on what scenarios you are looking at.
-
Mar 19th, 2011, 04:11 PM
#3
Thread Starter
Junior Member
Re: Register/login System
ok im going with the first option,
how do you call something from a module to a form?
i guessed a couple times but i failed...
-
Mar 19th, 2011, 05:30 PM
#4
Re: Register/login System
Can you be more specific with "something"? It's really easy but depends on what you are referring to
-
Mar 19th, 2011, 06:08 PM
#5
Thread Starter
Junior Member
Re: Register/login System
I just copied this from a game login, could i use this to make the contents of the form save and make a login?
I edited all the locations so it goes to the folder i want it to
Code:
Function AccountExist(ByVal name As String) As Boolean
Dim filename As String
filename = "\Ea\" & Trim(name) & ".ini"
If FileExist(filename) Then
AccountExist = True
End If
End Function
Function PasswordOK(ByVal name As String, ByVal Password As String) As Boolean
Dim filename As String
Dim RightPassword As String * NAME_LENGTH
Dim nFileNum As Long
If AccountExist(name) Then
filename = App.Path & "\Ea\" & Trim$(name) & ".ini"
nFileNum = FreeFile
Open filename For Binary As #nFileNum
Get #nFileNum, ACCOUNT_LENGTH, RightPassword
Close #nFileNum
If UCase$(Trim$(Password)) = UCase$(Trim$(RightPassword)) Then
PasswordOK = True
End If
End If
End Function
Sub AddAccount(ByVal index As Long, ByVal name As String, ByVal Password As String)
Dim i As Long
ClearPlayer index
Player(index).Login = name
Player(index).Password = Password
Call SavePlayer(index)
End Sub
Sub SavePlayer(ByVal index As Long)
Dim filename As String
Dim f As Long
filename = App.Path & "\Ea\" & Trim$(Player(index).Login) & ".ini"
f = FreeFile
Open filename For Binary As #f
Put #f, , Player(index)
Close #f
End Sub
-
Mar 19th, 2011, 06:14 PM
#6
Re: Register/login System
It really depends on what you want saved. That example appears to save a UDT (user defined type) to file, per user account. An INI file can be simple or complex. You should first determine what exactly you want to save. Then it's a matter of saving: create file, write contents, close file. When time comes to read: Open file if it exists, read contents, close file. How you write the contents dictates how you read/parse the contents.
-
Mar 19th, 2011, 06:26 PM
#7
Thread Starter
Junior Member
Re: Register/login System
yeah i was going for a udt account
so how would i call AddAccount in a form if it's in a module?
-
Mar 19th, 2011, 06:29 PM
#8
Re: Register/login System
In the module, simple declare the AddAccount routine as PUBLIC. Any publicly delcared variable, function, sub, property in a module can be called from anywhere within your project, at any time. Note that not including the Public or Private keyword makes it Public by default.
-
Mar 20th, 2011, 12:26 AM
#9
Thread Starter
Junior Member
Re: Register/login System
So i said screw the game one, and i made my own can someone revise it for me?
Code:
Public Sub CreateUser()
' ' ' ' ' ' ' ' ' ' ' ' '
' ' ' Create User ' ' ' '
' ' ' ' ' ' ' ' ' ' ' ' '
Dim Username, Password As String
Username = Form2.Text1.Text
Password = Form2.Text3.Text
Open App.Path & "/Ea/" & Username & ".ini" For Output As info
Print info, Username
Print info, Password
Close info
Exit Sub
End Sub
Public Sub Login()
''''''''''''''''''
' ' ' LOGIN' ' ' '
''''''''''''''''''
On Error GoTo err
Dim Username As String
Dim Password As String
Dim CorrUser As String
Dim CorrPass As String
Username = frmLogin.txtUserName.Text
Password = frmLogin.txtPassword.Text
Open App.Path & "/Ea/" & Username & ".ini" For Input As #Login
Input #Login, CorrUser
Input #Login, CorrPass
Close #Login
If Username = "" Then MsgBox "Please Enter a Valid Username.", vbOKOnly, "Login Failed"
ElseIf Username = CorrUser Then
If CorrPass <> Password Then MsgBox "Invalid Password", vbOKOnly, "Login Failed"
ElseIf Password = CorrPass Then
MsgBox "Welcome " + Username
Me.Hide
Form3.Show
Else
End If
Else
End If
Exit Sub
err: MsgBox "Login Failed Try Again", vbCritical, "Login Failed"
End Sub
-
Mar 20th, 2011, 12:44 AM
#10
Thread Starter
Junior Member
Re: Register/login System
So i tried to use the code in my previous relpy as a module, and when i activate it on the form it comes up with an error,
it says:
"Compile Error:
Method not valid without suitable object"
and highlights this portion:
Code:
Print info, Username
Extra info:
This code is in Public Sub CreateUser()
I am using a command button to call this
Code:
Command3_click()
Call CreateUser
Please Help
Previous Reply:
 Originally Posted by Willbillion
So i said screw the game one, and i made my own can someone revise it for me?
Code:
Public Sub CreateUser()
' ' ' ' ' ' ' ' ' ' ' ' '
' ' ' Create User ' ' ' '
' ' ' ' ' ' ' ' ' ' ' ' '
Dim Username, Password As String
Username = Form2.Text1.Text
Password = Form2.Text3.Text
Open App.Path & "/Ea/" & Username & ".ini" For Output As info
Print info, Username
Print info, Password
Close info
Exit Sub
End Sub
Public Sub Login()
''''''''''''''''''
' ' ' LOGIN' ' ' '
''''''''''''''''''
On Error GoTo err
Dim Username As String
Dim Password As String
Dim CorrUser As String
Dim CorrPass As String
Username = frmLogin.txtUserName.Text
Password = frmLogin.txtPassword.Text
Open App.Path & "/Ea/" & Username & ".ini" For Input As #Login
Input #Login, CorrUser
Input #Login, CorrPass
Close #Login
If Username = "" Then MsgBox "Please Enter a Valid Username.", vbOKOnly, "Login Failed"
ElseIf Username = CorrUser Then
If CorrPass <> Password Then MsgBox "Invalid Password", vbOKOnly, "Login Failed"
ElseIf Password = CorrPass Then
MsgBox "Welcome " + Username
Me.Hide
Form3.Show
Else
End If
Else
End If
Exit Sub
err: MsgBox "Login Failed Try Again", vbCritical, "Login Failed"
End Sub
-
Mar 20th, 2011, 11:27 AM
#11
Re: Register/login System
The Print command requires an object or file number
Object: Picture1.Print userName will print the username value to the picturebox. In a form, the form is default if no object provided. In a module, you must provide the object or file handle
File number: Print #1, userName will print the username value to an opened file
You should avoid hardcoding file numbers, rather use FreeFile() to return one. Look at the VB FAQs linked in my signature below. There are good examples you can use for file I/O.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|