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:
Public Function ChangePassword_Click(ByVal password As String, ByVal start As Integer, ByVal length As Integer, ByVal studentpass2 As String) As String
studentpass1 = InputBox("Please enter your previous password.")
studentpass2 = InputBox("Please enter your new password.")
If start + length >= Len(password) Then
DeleteSubString = Left(password, start - 1)
Else
DeleteSubString = Left(password, start) & Mid(password, start + length + 1)
End If
InsertSubString = Left(password, start - 1) & studentpass2 & Mid(password, start)
MsgBox ("You have successfully changed your password"), vbExclamation
End Function
I have also tried this:
Private Sub cmdchangepassword( ) Click
Function (byVal username as String, ByVal password as String, ByVal studentpass1 as String, ByVal studentpass2 as String) as String
Replace (password, studentpass1, studentpass2
End Function
Nothing is working!!!
Re: Deleting certain parts of a text file
whats the format of the text file?
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.
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.
Re: Deleting certain parts of a text file