Results 1 to 5 of 5

Thread: Deleting certain parts of a text file

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Question Deleting certain parts of a text file

    I am creating a childrens program where the user has an opportunity to change their password or delete an account. The information is inside a text file and i don't know how to delete only the password etc... At the moment my code is:
    vb Code:
    1. Public Function ChangePassword_Click(ByVal password As String, ByVal start As Integer, ByVal length As Integer, ByVal studentpass2 As String) As String
    2.     studentpass1 = InputBox("Please enter your previous password.")
    3.     studentpass2 = InputBox("Please enter your new password.")
    4.         If start + length >= Len(password) Then
    5.             DeleteSubString = Left(password, start - 1)
    6.         Else
    7.             DeleteSubString = Left(password, start) & Mid(password, start + length + 1)
    8.         End If
    9.         InsertSubString = Left(password, start - 1) & studentpass2 & Mid(password, start)
    10. MsgBox ("You have successfully changed your password"), vbExclamation
    11. End Function
    12. I have also tried this:
    13. Private Sub cmdchangepassword( ) Click
    14. Function (byVal username as String, ByVal password as String, ByVal studentpass1 as String, ByVal studentpass2 as String) as String
    15.     Replace (password, studentpass1, studentpass2
    16. End Function
    Nothing is working!!!
    Last edited by Hack; Oct 22nd, 2007 at 06:37 AM. Reason: Added Highlight Tags

  2. #2
    Member
    Join Date
    Sep 2007
    Location
    Lictin
    Posts
    36

    Re: Deleting certain parts of a text file

    whats the format of the text file?

  3. #3
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Deleting certain parts of a text file

    Read the text file into memory.
    Write it to a new file using the new password.
    Erase the old file.
    Rename the new file as the old one.
    The effect will be as if you'd actually changed the line where the password resided.
    Remember to make a backup of the original file until you're quite sure your code is working.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Deleting certain parts of a text file

    you will either have to do it like he just said, or you will have to create your textfile with fixed field lengths and edit it in binary or random mode.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    14

    Re: Deleting certain parts of a text file

    Ok, i'll try that thanks

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