-
Jan 7th, 2012, 08:14 AM
#1
Thread Starter
Addicted Member
Changing a data entity in .txt file
hi, So I have a list box that gets its entities from a .txt file which are listed one by one (each entity being on a new line of the .txt file)
How would I go about changing one of the entities?
Here is the code I have at the moment which seems to just delete everything in the file and then enters only the information that has been changed.
Code:
Open (File0.Path & "\" & File0.FileName) For Input As #1
i = 0
Do While Not EOF(1)
Input #1, x(i)
i = i + 1
Loop
Close #1
Open (File0.Path & "\" & File0.FileName) For Output As #1
i = 0
If lst0.ListIndex = 0 Then
Write #1, Hair0.Text
i = i + 1
End If
Do
Write #1, x(i)
i = i + 1
If lst0.ListIndex = i Then
Write #1, Hair0.Text
i = i + 1
End If
Loop Until i = lst0.ListCount
Close #1
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Jan 7th, 2012, 12:14 PM
#2
Re: Changing a data entity in .txt file
The If statement before the Do...Loop has no meaning, try the following code
vb Code:
Open (File0.Path & "\" & File0.FileName) For Input As #1 i = 0 Do While Not EOF(1) Input #1, x(i) i = i + 1 Loop Close #1 Open (File0.Path & "\" & File0.FileName) For Output As #1 i = 0 Do If lst0.ListIndex = i Then Write #1, Hair0.Text Else Write #1, x(i) End If i = i + 1 Loop Until i = lst0.ListCount Close #1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|