-
Apr 22nd, 2006, 05:03 PM
#1
Thread Starter
Frenzied Member
-
Apr 22nd, 2006, 05:18 PM
#2
Re: Delete Multiple Lines From Text File!
Why not store them in two different text files. For example "Non IE Favorites.txt" and "IE favorites.txt".
Jenova
-
Apr 22nd, 2006, 06:35 PM
#3
Thread Starter
Frenzied Member
-
Apr 22nd, 2006, 07:08 PM
#4
Re: Delete Multiple Lines From Text File!
Why does it have to be a text file? Save it as a data file with url and "IsFromIE" fields.
-
Apr 22nd, 2006, 09:32 PM
#5
Thread Starter
Frenzied Member
Re: Delete Multiple Lines From Text File!
Why does it have to be a text file? Save it as a data file with url and "IsFromIE" fields.
What difference will that make? I can do the same in a text file as well........
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
-
Apr 22nd, 2006, 10:15 PM
#6
Lively Member
Re: Delete Multiple Lines From Text File!
try this:
step 1: save each favorite into an array
step 2: rewrite the text file line by line, comparing each line to the string representing the deleted favorite
step 3: if the favorite from the array is equal to the deleted favorite, skip to the next variable in the array.
step 4: when the loop is complete, your new favorites file will not have the deleted favorite
step 5: update the menu
here is the code:
VB Code:
public sub deletefavorite()
' build a variable containing all of the favorites
open favoritefile for input as #1
do while not eof(1)
line input #1, x
fav = fav & "`" & x
loop
close
'convert the variable into an array
array = split(fav, "`")
'clear the file of favorites
open favoritefile for output as #1
print #1, ""
close
'the loop rebuilding the file, excluding the deleted favorite
for a = lbound(array) to ubound(array)
if favorite_to_be_deleted = array(a) then goto 1
open favoritefile for append as #1
print #1, array(a)
close
1 next a
end sub
-
Apr 23rd, 2006, 01:47 AM
#7
Thread Starter
Frenzied Member
Re: Delete Multiple Lines From Text File!
Thanks, mate, you have given me a great suggestion. This is what I did finally (each of the IE Favorites, when added to the text file, were appended with ^^^^^ at the very end):
VB Code:
Private Sub DeleteIEFavorites()
Dim i As Integer
Dim str As String
Dim Fav As String
Dim iFile As Integer
Dim FileName As String
Dim arrFav() As String
iFile = FreeFile
FileName = App.Path & "\Favorites.txt"
Open FileName For Input As #iFile
Do While Not EOF(iFile)
Line Input #iFile, str
Fav = Fav & "`" & str
Loop
Close
arrFav = Split(Fav, "`")
Open FileName For Output As #iFile
Close
For i = 0 To UBound(arrFav)
If (arrFav(i) <> vbNullString And InStrRev(arrFav(i), "^^^^^") = 0) Then
Open FileName For Append As #iFile
Print #iFile, arrFav(i)
Close #iFile
End If
Next i
End Sub
Now the IE Favorites are getting deleted & at the same time, the Favorites exclusively added by the user remain in the text file.
I must once again confess that you really gave me a fantastic idea
Thanks once again.............
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
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
|