| View previous topic :: View next topic |
| Author |
Message |
$watto Newbie

Joined: 09 Apr 2004 Posts: 10
|
Posted: Apr 9th, 2004 04:38 PM Post subject: How do i make my application create a file.... |
|
|
hi again, im still on my login screen project:
i would like to know how i can make my application (when it loads) check if a txt file exists in a specified directory and if it doesnt then create the file within that directory with default txt inside.
i then want my application to read the text inside the *.txt file to see if the text the user has entered matches the txt inside the file and if it doesnt then obviously the password entered is wrong
thanks for any help :devil: _________________ There are only 10 types of people in the world: those who understand binary, and those who don't
Location:01000101,01001110,01000111,01001100,01000001,01001110,01000100 |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Apr 9th, 2004 05:02 PM Post subject: |
|
|
To check if a file exists, you can use the following function :
[vb:1:4b0f46933f]Private Function FileExists(sFileName As String) As Boolean
If Len(Dir$(sFileName)) Then
FileExists = True
End If
End Function[/vb:1:4b0f46933f]
Here's an example :
[vb:1:4b0f46933f]Private Sub Form_Load()
MsgBox FileExists("C:\test.txt")
End Sub[/vb:1:4b0f46933f]
Now, are you planning to have one file per user or one file and store all the usernames/passowords? _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
$watto Newbie

Joined: 09 Apr 2004 Posts: 10
|
Posted: Apr 9th, 2004 05:04 PM Post subject: |
|
|
im just going to have 1 password stored in the file, but when the user wants to change the password i want the password updated in the file _________________ There are only 10 types of people in the world: those who understand binary, and those who don't
Location:01000101,01001110,01000111,01001100,01000001,01001110,01000100 |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Apr 9th, 2004 05:14 PM Post subject: |
|
|
Well, here's a simple example :
[vb:1:1dd4fcb04e]Option Explicit
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
Const Path As String = "C:\Your App\Users\" 'Change this to whatever you want
Private Sub Form_Load()
MakeFile "PTAM", "passwd"
MsgBox GetPassword("PTAM")
End Sub
Private Sub MakeFile(sUserName As String, sPassword As String)
Dim FF As Integer
MakeSureDirectoryPathExists Path 'This is just to make sure the directory you are putting the files exists
'If you don't do this, you get a Path not found error
FF = FreeFile
Open Path & sUserName & ".txt" For Output As #FF
Print #FF, sPassword
Close #FF
End Sub
Private Function GetPassword(sUserName As String) As String
Dim FF As Integer
MakeSureDirectoryPathExists Path 'This is just to make sure the directory you are putting the files exists
'If you don't do this, you get a Path not found error
FF = FreeFile
Open Path & sUserName & ".txt" For Input As #FF
GetPassword = Trim$(Input(LOF(FF), FF))
Close #FF
End Function[/vb:1:1dd4fcb04e] _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
$watto Newbie

Joined: 09 Apr 2004 Posts: 10
|
Posted: Apr 9th, 2004 05:32 PM Post subject: |
|
|
i dont understand how to edit the different parts of the code to fit in with my project, or where to put each part, i think im getting a bit to ahead of myself with my learning :$ _________________ There are only 10 types of people in the world: those who understand binary, and those who don't
Location:01000101,01001110,01000111,01001100,01000001,01001110,01000100 |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Apr 9th, 2004 05:58 PM Post subject: |
|
|
I saw your project and I am a bit confused... You don't seem to have a box for username... Do you only want to save a password and retrieve that or have a multi user login feature, with create user screens and stuff like that?  _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
$watto Newbie

Joined: 09 Apr 2004 Posts: 10
|
Posted: Apr 9th, 2004 06:06 PM Post subject: |
|
|
all i want to do is save a single password and retrieve it (i dont want a user or anything like that because its too advanced for me at the moment) i would also like something in my application where if a user wants to change the password they enter the current password, then the new password, which then overwrites the old password in the file so next time the program loads up it checks the file for the updated password _________________ There are only 10 types of people in the world: those who understand binary, and those who don't
Location:01000101,01001110,01000111,01001100,01000001,01001110,01000100 |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Apr 9th, 2004 06:13 PM Post subject: |
|
|
Sorry, I missunderstood what you wanted :$ Then this simplifies things
[vb:1:5c201259bf]Option Explicit
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
Const Path As String = "C:\Your App\Users\password.txt" 'Change this to whatever you want, this is the file that the password will be saved to
Private Sub Form_Load()
MakeFile "PTAM", "passwd"
MsgBox GetPassword("PTAM")
End Sub
Private Sub ChangePassword(sPassword As String)
Dim FF As Integer
MakeSureDirectoryPathExists Path 'This is just to make sure the directory you are putting the files exists
'If you don't do this, you get a Path not found error
FF = FreeFile
Open Path For Output As #FF
Print #FF, sPassword
Close #FF
End Sub
Private Function GetPassword() As String
Dim FF As Integer
MakeSureDirectoryPathExists Path 'This is just to make sure the directory you are putting the files exists
'If you don't do this, you get a Path not found error
FF = FreeFile
Open Path For Input As #FF
GetPassword = Trim$(Input(LOF(FF), FF))
Close #FF
End Function[/vb:1:5c201259bf]]
How about this?  _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
$watto Newbie

Joined: 09 Apr 2004 Posts: 10
|
Posted: Apr 9th, 2004 06:22 PM Post subject: |
|
|
thanks, but it says: Sub or Function not defined for MakeFile
if u still have my project is there any chance u could input the code in the different parts of the project im sorry if that is cheeky and u have been very helpful so far, but ive got two seperate forms and i dont know which functions have to go where and in which forms >_< _________________ There are only 10 types of people in the world: those who understand binary, and those who don't
Location:01000101,01001110,01000111,01001100,01000001,01001110,01000100 |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Apr 9th, 2004 06:39 PM Post subject: |
|
|
OK, here is a working example  _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
$watto Newbie

Joined: 09 Apr 2004 Posts: 10
|
Posted: Apr 9th, 2004 06:48 PM Post subject: |
|
|
thankyou very much, im really sorry for being a pain, im just really new to VB so i wasnt sure where certain things go, im going to analyze the code now so i can learn for next time :happy: _________________ There are only 10 types of people in the world: those who understand binary, and those who don't
Location:01000101,01001110,01000111,01001100,01000001,01001110,01000100 |
|
| Back to top |
|
P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Apr 9th, 2004 06:54 PM Post subject: |
|
|
No problem
See ya ^_^ _________________ No one is completely useless. They can at least be an example of what to avoid. |
|
| Back to top |
|
|