Output to text file Appending instead of Printing

lurch
04-25-2003, 03:53 AM
Here is the code I'm using to print to a text file.
Instead of the new data Printing over the old data it appends/adds to the bottom of the old data...I can't see why.

'WebBrowser data Refreshes every 10 seconds

txtScript = WebBrowser1.Document.documentElement.innertext

Open "c:\tempRace.txt" For Output As #1
Print #1, txtScript
Close #1

'*******Copies data from tempRace.txt to testRace.txt******

Open "c:\tempRace.txt" For Input As #2
Open "c:\testRace.txt" For Output As #3
Do While Not EOF(2)
Line Input #2, strLine
If InStr(strLine, ".") > 10 Then
send = send & strLine & vbCrLf
End If
Loop

Print #3, send
Close #3
Close #2


This is the result in the testRace text file after Refreshing once:

1BELJAY ASSASSIN $ 2.30$ 2.80$ 2.30$ 2.40$ 1.00
2PARTY STARTER $ 5.70$ 5.60$ 7.80$11.10$ 3.00
4LEGEND DOZER $ 8.30$ 8.60$ 6.90$ 6.20$ 2.30
5VOODOO FLASH $20.70$11.10$10.40$14.30$ 3.90
6EBONY CLOSE $17.80$21.80$25.00$20.30$ 3.70
7ROAD DANCER $ 9.30$ 5.20$ 6.30$ 9.10$ 2.30
8STUMPY'S REVENGE $ 4.10$ 4.90$ 5.50$ 3.60$ 1.20
**Added empty row to show duplication**
1BELJAY ASSASSIN $ 2.30$ 2.30$ 2.40$ 2.50$ 1.00
2PARTY STARTER $ 5.70$ 7.80$11.10$10.60$ 3.20
4LEGEND DOZER $ 8.30$ 6.90$ 6.20$ 7.10$ 2.40
5VOODOO FLASH $20.70$10.40$14.30$12.40$ 3.50
6EBONY CLOSE $17.80$25.00$20.30$19.30$ 3.50
7ROAD DANCER $ 9.30$ 6.30$ 9.10$ 7.70$ 2.40
8STUMPY'S REVENGE $ 4.10$ 5.50$ 3.60$ 3.60$ 1.20

SSJ Vegetto
04-25-2003, 04:14 AM
Hi there....

There Are Several Ways to copy a file...examples:


'This function automaticaly overwrites the old values...
Open "c:\testRace.txt" For Output As #1
Print #1, WebBrowser1.Document.documentElement.innertext
Close #1

Or

Open "c:\tempRace.txt" For Output As #1
Print #1, WebBrowser1.Document.documentElement.innertext
Close #1

If Dir("C:\textRace.txt") <> "" Then

End If

SSJ Vegetto
04-25-2003, 04:17 AM
Hi there....

There Are Several Ways to copy a file...examples:


'This function automaticaly overwrites the old values...
Open "c:\testRace.txt" For Output As #1
Print #1, WebBrowser1.Document.documentElement.innertext
Close #1

Or

Open "c:\tempRace.txt" For Output As #1
Print #1, WebBrowser1.Document.documentElement.innertext
Close #1

'Check if file exists else remove file from HD
If Dir("C:\testRace.txt") <> "" Then
Kill "C:\testRace.txt"
End If

'Use This one
Name "C:\tempRace.txt" As "C:\testRace.txt"
'Or use this one
FileCopy "C:\tempRace.txt", "C:\testRace.txt"


Gr. Bob

starbitz
04-25-2003, 04:27 AM
I copied the structure of your code and provide my own text. It works fine in me. I think it is the "send" variable of yours that is causing the problem. Try initializing your "send" variable = "" before copying the data. :)
Open "c:\tempRace.txt" For Input As #2
Open "c:\testRace.txt" For Output As #3
send = "" '<-- maybe you can initialize it here
Do While Not EOF(2)
Line Input #2, strLine
If InStr(strLine, "." ) > 10 Then
send = send & strLine & vbCrLf
End If
Loop

Print #3, send
Close #3
Close #2

lurch
04-25-2003, 04:44 AM
Hi there....

There Are Several Ways to copy a file...examples:


'This function automaticaly overwrites the old values...
Open "c:\testRace.txt" For Output As #1
Print #1, WebBrowser1.Document.documentElement.innertext
Close #1

Or

Open "c:\tempRace.txt" For Output As #1
Print #1, WebBrowser1.Document.documentElement.innertext
Close #1

If Dir("C:\textRace.txt") <> "" Then

End If



Thankyou for your response.

It didn't fix my problem but it gave an alternative to do something else.

lurch

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum