Furkan
05-10-2003, 05:38 PM
Dear all,
I have the following code to open a txt file and delete all spaces in it. Only the rows wich begins with HHH we do not delete the spaces in it:
myFile1 = FreeFile
Open "c:\test\test.txt" For Input As #myFile1
mijnFile2 = FreeFile
Open "c:\test\send\test.txt" For Output As #mijnFile2
Do While Not EOF(myFile1)
Line Input #myFile1, strSearch
If Not Mid(strSearch, 1, 3) = "HHH" Then
strSearch = Replace(strSearch, " ", "")
End If
Print #myFile2, strSearch
Loop
Close #myFile2
Close #myFile1
Only now i must make more modifications in it. I shall explain the situation and hope the experts here give me the right way.
The txt files always begins with a AAA, BBB lettercombination and ends with ZZZ. I must delete all AAA,BBB and ZZZ rows without the first AAA, BBB and the ZZZ at the end. Here is the situation:
AAA
BBB
CCC
DDD
EEE
FFF
GGG
HHH
AAA
BBB
CCC
DDD
ZZZ
III
ZZZ
must be:
AAA
BBB
CCC
DDD
EEE
FFF
GGG
HHH
CCC
DDD
III
ZZZ
Any idea's.
Thanks in advance...
Banjo
05-11-2003, 12:55 PM
For the first AAA and BBB you can simply use a pair of boolean flags to indicate whether or not the first sequences have been read.
As for the final ZZZ that depends on whether the fie always ends with ZZZ. Can there be anything else after that? If not then you can simply ignore all ZZZ combinations and once the EOF is reached output a ZZZ sequence.
If the file does not have to end with ZZZ then do you still want the final ZZZ sequence removed?
If not again you need a boolean flag. Set it to true whenever you read ZZZ and to false whenever you read something else. If the EOF loop ends with the flag set then write the ZZZ else don't.
If you do want the final ZZZ removed regardless then you will need to accumulate the data to be written after you read a ZZZ. Basically, whenever you read a ZZZ store it and a terminating vbCrLf in a string variable. Continue reading from the file but instead of writing out to the output file append the read data to the string (remembering to add a vbcrlf to each line). When the next ZZZ is read, write the string variable to the output file and then start the accumlation process again.
Once the EOF is reached if there is data in the string buffer then use the Mid$ function to remove the initial ZZZ and then write it to the output file.
Furkan
05-11-2003, 01:45 PM
Could you pls put this in code, i'm not so good in VB. Thanks a lot for your support. I appreciate that very much..
Banjo
05-11-2003, 02:17 PM
Why don't you give it a try and then ask for help you have any problems. Oh, and which of the three scenarios that I outlined are you wishing to achieve?
Furkan
05-12-2003, 06:29 AM
For the first AAA and BBB you can simply use a pair of boolean flags to indicate whether or not the first sequences have been read.
As for the final ZZZ that depends on whether the fie always ends with ZZZ. Can there be anything else after that? If not then you can simply ignore all ZZZ combinations and once the EOF is reached output a ZZZ sequence.
No beneath the ZZZ combination there isn’t anything, The row which begins with the ZZZ combination will be the last row. But we couldn’t ignore all ZZZ and put the ZZZ at the end because after the letter combinations can something stay, something like this:
AAA 123 4 55 6 6 6 6
BBB abc cnd, dfk ‘
LLL bbb kkk lll mmm
ZZZ xxx 12 3 4
If the file does not have to end with ZZZ then do you still want the final ZZZ sequence removed?
I must not remove the last ZZZ combination, I must delete the rows which begins with ZZZ between the first AAA BBB and the last ZZZ.
If not again you need a boolean flag. Set it to true whenever you read ZZZ and to false whenever you read something else. If the EOF loop ends with the flag set then write the ZZZ else don't.
If you do want the final ZZZ removed regardless then you will need to accumulate the data to be written after you read a ZZZ. Basically, whenever you read a ZZZ store it and a terminating vbCrLf in a string variable. Continue reading from the file but instead of writing out to the output file append the read data to the string (remembering to add a vbcrlf to each line). When the next ZZZ is read, write the string variable to the output file and then start the accumlation process again.
Once the EOF is reached if there is data in the string buffer then use the Mid$ function to remove the initial ZZZ and then write it to the output file.
Summarized: I must delete all AAA BBB and ZZZ rows between the first AAA, BBB and the last ZZZ. I hope I’m clearly enough. Could you give your example in a code, because I’m a newbie in VB, I hope you can understand me. Thanks a lot…
Banjo
05-12-2003, 02:25 PM
you can simply ignore all ZZZ combinations and once the EOF is reached output a ZZZ sequence.
That is the scheme that you need to follow, but with a slight modifcation. Whenever you read a line starting ZZZ store it in a string variable. Do this every time, overwriting the last one each time. Once your reach EOF output the last stored ZZZ line.
Furkan
05-13-2003, 10:44 AM
That is the scheme that you need to follow, but with a slight modifcation. Whenever you read a line starting ZZZ store it in a string variable. Do this every time, overwriting the last one each time. Once your reach EOF output the last stored ZZZ line.
I want not to be irritant but i'm not so good in VB and i think it is very very difficult for me to do this. That is the reasen why i'm asking for the experts. I hope you can understand me and give me the right way. Thanks a lot.
Furkan
05-19-2003, 01:44 AM
That is the scheme that you need to follow, but with a slight modifcation. Whenever you read a line starting ZZZ store it in a string variable. Do this every time, overwriting the last one each time. Once your reach EOF output the last stored ZZZ line.
I want not to be irritant but i'm not so good in VB and i think it is very very difficult for me to do this. That is the reasen why i'm asking for the experts. I hope you can understand me and give me the right way. Thanks a lot.
ANYBODY IDEA'S?