Results 1 to 11 of 11

Thread: [RESOLVED] Write to the SECOND line in a text file?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    97

    Resolved [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:
    1. Sub addpw()
    2.  Dim ff%, i%
    3.  ReDim user(0)
    4.  ReDim pass(0)
    5.  index = 0
    6.  user(0) = InputBox("Enter User Name")
    7.  pass(0) = InputBox("Enter Password")
    8.  maxindex = 1
    9.  ff = FreeFile
    10.  Open (App.Path & "\login.txt") For Output As #ff
    11.  For i = 0 To maxindex - 1
    12.  Print #ff, StrToHex(user(i)) & " | " & StrToHex(pass(i))
    13.  Next i
    14.  Close #ff

    And I would call it to add the text by doing so:
    VB Code:
    1. Private Sub Form_Load()
    2. Call addpw
    3. user(0) = "Username"
    4. pass(0) = "Password"
    5. 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:
    1. Form_Load()
    2. Call addpw
    3. user(0) = "Username"
    4. pass(0) = "Password"
    5. user(1) = "Username1"
    6. pass(1) = "Password1"
    7. user(2) = "Username2"
    8. pass(2) = "Password2"
    9. 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.
    Last edited by Echo{tWe}; Jun 11th, 2005 at 09:12 PM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    97

    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?

  4. #4
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    97

    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.

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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
    Attached Files Attached Files
    Last edited by dglienna; Jun 11th, 2005 at 01:30 PM.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    97

    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.
    Last edited by Echo{tWe}; Jun 11th, 2005 at 07:01 PM.

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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:
    1. user(idx) = HexToStr(xline(0))
    2.   pass(idx) = HexToStr(xline(1))
    3.   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:

    VB Code:
    1. Dim i%, ff%, idx%

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    97

    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:
    1. user(idx) = HexToStr(xline(0))
    2.   pass(idx) = HexToStr(xline(1))
    3.   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:

    VB Code:
    1. Dim i%, ff%, idx%
    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?

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.
    Attached Files Attached Files

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    97

    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 .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width