[RESOLVED] Write to the SECOND line in a text file?
Hello, I'm kind of troubled by this. How do I write to the second line of the text file? I'm using this code, to add encrypted text (in hex) to line one, and read it and validate it. I need to know how to add it to line 2, 3, 4, ect. Thank you for your help.
VB Code:
Sub addpw()
Dim ff%, i%
ReDim user(0)
ReDim pass(0)
index = 0
user(0) = InputBox("Enter User Name")
pass(0) = InputBox("Enter Password")
maxindex = 1
ff = FreeFile
Open (App.Path & "\login.txt") For Output As #ff
For i = 0 To maxindex - 1
Print #ff, StrToHex(user(i)) & " | " & StrToHex(pass(i))
Next i
Close #ff
And I would call it to add the text by doing so:
VB Code:
Private Sub Form_Load()
Call addpw
user(0) = "Username"
pass(0) = "Password"
End Sub
The bottom calls the top code, to add "Username" and "Password" encrypted in hex, on the first line of a text file. I need to be able to add it to the second line so I could do something like:
VB Code:
Form_Load()
Call addpw
user(0) = "Username"
pass(0) = "Password"
user(1) = "Username1"
pass(1) = "Password1"
user(2) = "Username2"
pass(2) = "Password2"
End Sub
I think you get the point, thanks alot guys :)
Also, once I have that done, how would I get it to check not only the first line, but the second one too, to validate it.
Re: Write to the SECOND line in a text file?
If you change the output to an append, it will write each password combination to the end of the password file, encrypted. When you are reading it back, you could read the whole file into a buffer, and split it on the vbCrLf, which would tell you how many user names that you have.
I would have a tUser as String and tPassword as string when they are entering the info. That way you could loop if tuser = user(x) and tpassword = password(x) for each password in the file.
Re: Write to the SECOND line in a text file?
Quote:
Originally Posted by dglienna
If you change the output to an append, it will write each password combination to the end of the password file, encrypted. When you are reading it back, you could read the whole file into a buffer, and split it on the vbCrLf, which would tell you how many user names that you have.
I would have a tUser as String and tPassword as string when they are entering the info. That way you could loop if tuser = user(x) and tpassword = password(x) for each password in the file.
Wow, I have no clue how to do that. Think you can show me an example?
Re: Write to the SECOND line in a text file?
this might be of some use to you, this will read inbetween lines, i think you could modify it accordingly using replace( or something.
Re: Write to the SECOND line in a text file?
Quote:
Originally Posted by |2eM!x
this might be of some use to you, this will read inbetween lines, i think you could modify it accordingly using replace( or something.
You didn't post anything.
1 Attachment(s)
Re: Write to the SECOND line in a text file?
Here is how to append the passwords and not keep overwriting the same one
You really can't make an app by just copy paste someone elses app, because they usually have different requirements. This one came from someone adding a password to their school assignment, and only needed one set of credentials. I would do things differently for more than one
I maade some changes to that app so that it would work with more than one user. the problem is that there is no main for that calls new password generation. i added David/Password and test/test. They both work
Re: Write to the SECOND line in a text file?
Quote:
Originally Posted by dglienna
Here is how to append the passwords and not keep overwriting the same one
You really can't make an app by just copy paste someone elses app, because they usually have different requirements. This one came from someone adding a password to their school assignment, and only needed one set of credentials. I would do things differently for more than one
I maade some changes to that app so that it would work with more than one user. the problem is that there is no main for that calls new password generation. i added David/Password and test/test. They both work
EDIT: Actually, it isn't working. test/test worked, but not David/Password, I tried some other combos too, but they failed.
Re: Write to the SECOND line in a text file?
Hmmm. I guess I should have tested better. Change these two lines:
It was only testing the last one, and I had tested the other two earlier.
Username/Password was the first one
VB Code:
user(idx) = HexToStr(xline(0))
pass(idx) = HexToStr(xline(1))
idx = idx + 1
It was using j, which was 0 each time. Also, you can delete the j% from the declaration so it's like this:
Re: Write to the SECOND line in a text file?
Quote:
Originally Posted by dglienna
Hmmm. I guess I should have tested better. Change these two lines:
It was only testing the last one, and I had tested the other two earlier.
Username/Password was the first one
VB Code:
user(idx) = HexToStr(xline(0))
pass(idx) = HexToStr(xline(1))
idx = idx + 1
It was using j, which was 0 each time. Also, you can delete the j% from the declaration so it's like this:
I tryed changing it, still didn't work. I may have done it wrong, see if it works for you, if it does, could you upload it?
1 Attachment(s)
Re: Write to the SECOND line in a text file?
You just had to replace two lines, but as long as i didn't erase it, i will zip it and post it again.
Re: Write to the SECOND line in a text file?
Quote:
Originally Posted by dglienna
You just had to replace two lines, but as long as i didn't erase it, i will zip it and post it again.
Thanks a bunch bro :).