473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

searching a text and deleting the line

hello everybody,

i'm having some problems searching a text file and then deleting the line.
since i used fileopen(), i can use the eof() function to loop through the
file, searching for the specified line. the problem is, once found, i can't
delete it because the filemode is in openmode.input.
is there a way to chance the openmode on the run?(if so, what is it?)
and maybe there is a simpler way to search a text file and deleting the line?

this is the code so far:
<begin code>
Dim foto As String = fotos.Item(positionarray)
Dim arrayitem, line As String
FileOpen(4, cpath & albumpath & album, OpenMode.Input)
Do While Not EOF(4)
line = LineInput(4)
If line = foto Then
FileClose(4)
PrintLine(4, "")
MsgBox("deleted line!")
Exit Do
End If
Loop
FileClose(4)
<end code>
any help would be greatly appriciated :)

thanks,
Nov 21 '05 #1
2 2362
In order to delete a line from a text file, you must read lines from
the file and write them to another file, except for the line you want
deleted. Once you complete the other file, you delete the original and
then rename the new one back to the original name.

Nov 21 '05 #2
You could use the replace word to search for the string you want and replace
it with an empty string "" , then over write the original file with the new
data

"angus" <an***@discussions.microsoft.com> wrote in message
news:1A**********************************@microsof t.com...
hello everybody,

i'm having some problems searching a text file and then deleting the line.
since i used fileopen(), i can use the eof() function to loop through the
file, searching for the specified line. the problem is, once found, i
can't
delete it because the filemode is in openmode.input.
is there a way to chance the openmode on the run?(if so, what is it?)
and maybe there is a simpler way to search a text file and deleting the
line?

this is the code so far:
<begin code>
Dim foto As String = fotos.Item(positionarray)
Dim arrayitem, line As String
FileOpen(4, cpath & albumpath & album, OpenMode.Input)
Do While Not EOF(4)
line = LineInput(4)
If line = foto Then
FileClose(4)
PrintLine(4, "")
MsgBox("deleted line!")
Exit Do
End If
Loop
FileClose(4)
<end code>
any help would be greatly appriciated :)

thanks,

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: flupke | last post by:
Hi, i'm having trouble with deleting elements from a list in a for loop ============== test program ============== el = print "**** Start ****" print "List = %s " % el index = 0 for line...
3
by: Thaynann | last post by:
is there a way to delete a block of text i have started by looking for the speicific line of text that starts the block by looking for teh index of it...but i cannot figure out out to remove...
2
by: Roberto Dias | last post by:
Hi all, What to do for searching for more than one string occurrence in the same string (this last are line of a text). I have used getline(), to get the text lines by means of WHILE loop and...
3
by: googleboy | last post by:
Hi there. I have defined a class called Item with several (about 30 I think) different attributes (is that the right word in this context?). An abbreviated example of the code for this is: ...
7
by: Mathew Hill | last post by:
I am a beginner to the more technical aspects of Microsoft Access (2000) and was wondering if any one can help. I have 3 buttons on a form which add, delete and search for a record. However, when I...
3
by: Paul H | last post by:
I have a text file that contains the following: ******************** __StartCustomerID_41 Name: Fred Smith Address: 57 Pew Road Croydon
46
by: DP | last post by:
hi, i've got a form, with a subform in it. i've got a delete button in the subform. the code i;ve got is; Private Sub cmdDeleteRecord_Click() msg = "Are you sure you want to delete this...
3
by: TonyJ | last post by:
Hello! I supposed to modify some text files. In the file(s) which consist of different section. In one section you might have Path = <Installation_path>. The program will then replace the text...
12
by: Alexnb | last post by:
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.