|
-
Jul 13th, 2000, 07:05 AM
#1
hi all,
lets say i have a text file, now i want to check if the last line equals to something.
if it does then erase it, replace it with a new one and the put it back (even better just add a sentence before it).
and if it doest exist then add it.
but i prefer just to add a line before the last line
thanks..
-
Jul 13th, 2000, 07:34 AM
#2
_______
<P>
this will overwrite the line you search for..
[code]
'the results are what you want.
'search a filefor a line of code
Option Explicit
Option Compare Text
Private Sub Form_Load()
Dim myArr() As Variant
Dim myVar As String
Dim i As Integer
Open "c:\try.txt" For Input As #1
Do Until EOF(1)
i = i + 1
ReDim Preserve myArr(1 To i) As Variant
Line Input #1, myVar
myArr(i) = myVar
myArr(i) = Trim(myArr(i))
If myArr(i) = "End Select" Then
myArr(i) = "jump off a cliff"
End If
Loop
Close #1
Open "c:\try.txt" For Output As #2
For i = 1 To i
Write #2, myArr(i)
Next
Close
End Sub
[\code]
[Edited by HeSaidJoe on 07-13-2000 at 08:48 AM]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jul 13th, 2000, 07:42 AM
#3
Hyperactive Member
Hello bzemer,
I don't know what you are meaning but I do think the next source will help you.
Private Sub Form_Load()
Dim SourceFile, TargetFile, Row As String
SourceFile = "c:\Source.Txt"
TargetFile = "c:\Target.Txt"
If Dir(TargetFile) <> "" Then Kill (TargetFile)
Open SourceFile For Input As #1
Open TargetFile For Append As #2
While Not EOF(1) 'read all lines of source file
Line Input #1, Row 'read a row
Print #2, Row 'write a row
Wend
End Sub
Nice regards,
Michelle
-
Jul 13th, 2000, 08:36 AM
#4
bugs""""""""""""""""
ok, i used the first code like this:
Function replace()
Dim myArr() As Variant
Dim myVar As String
Dim i As Integer
Open "c:\_test.html" For Input As #1
Do Until EOF(1)
i = i + 1
ReDim Preserve myArr(1 To i) As Variant
Line Input #1, myVar
myArr(i) = myVar
myArr(i) = Trim(myArr(i))
If myArr(i) = "</body></html>" Then
myArr(i) = ""
End If
Loop
Close #1
Open "c:\_test.html" For Output As #2
For i = 1 To i
Write #2, myArr(i)
'MsgBox myArr(i)
Next
Close
End Function
and it does finds </body></html> and removes them.
and i can build the html like i wanted.
but..:
the html gets filled with """"""""" everywere.
i cant figure why
here is what i got:
"""<html><body>"""
"""<title></title>"""
""""""
"""<text='0000ff'><h7>5</h7> <br>"""
""""""
"<text='0000ff'><h7>5</h7> <br>"
""
<text='ffffff'><h7>Total: 10
<br>---------------------
</h7>
</body></html>
please help?
-
Jul 13th, 2000, 08:40 AM
#5
_______
<?>
That is because the file is saving as a comma delimited text file...
How to get around it is another question for which
I don't have the answer...I'll look around incase
you can't get it here.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jul 13th, 2000, 08:47 AM
#6
oh..
well.. please do so if you can, the chances that i would find the answere my self are pretty low..
thanks..
-
Jul 13th, 2000, 08:54 AM
#7
Fanatic Member
The problem lays in the choice of the Write Statement. This inserts quotation marks and commas between strings. Use the Print statement to write the file back instead.
From MSDN
Unlike the Print # statement, the Write # statement inserts commas between items and quotation marks around strings as they are written to the file. You don't have to put explicit delimiters in the list. Write # inserts a newline character, that is, a carriage return–linefeed (Chr(13) + Chr(10)), after it has written the final character in outputlist to the file.
Iain, thats with an i by the way!
-
Jul 13th, 2000, 10:14 AM
#8
_______
yup...same answer as I found.
Thanks...
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
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
|