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?
Printable View
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?
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.
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...
Can you be more specific with "something"? It's really easy but depends on what you are referring to
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
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.
yeah i was going for a udt account
so how would i call AddAccount in a form if it's in a module?
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.
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
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:
Extra info:Code:Print info, Username
This code is in Public Sub CreateUser()
I am using a command button to call thisPlease HelpCode:Command3_click()
Call CreateUser
Previous Reply:
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.