Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append to file problems....

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
GB
I'm trying to append to the end of a log file but misc characters appear once the data has been transferred...

Private Sub Command1_Click()

n = (Chr(13) & Chr(10) & "*****" & Chr(13) & Chr(10) & "Monday 15 July 2001" & Chr(13) & Chr(10) & "Testing This" & Chr(13) & Chr(10) & "Hope it works")

Open "U:\New.Txt" For Binary As #1
Put #1, LOF(1) + 1, n
Close #1
End Sub

The result in New.txt is...

 9
*****
Monday 15 July 2001
Testing This
Hope it works 9
*****
Monday 15 July 2001
Testing This
Hope it works 9
*****
Monday 15 July 2001
Testing This
Hope it works 9
*****
Monday 15 July 2001
Testing This
Hope it works

... it always adds the box, space, 9 when it restarts. How can I stop it doing this?

Thanks...
 
Don't know where it is comming from. Tested your code on my machine, and it doesn't display it.
David Paulson


 
I got the same problem so I tried this and it workes:

Private Sub Command1_Click()

n = (Chr(13) & Chr(10) & "*****" & Chr(13) & Chr(10) & "Monday 15 July 2001" & Chr(13) & Chr(10) & "Testing This" & Chr(13) & Chr(10) & "Hope it works")
If Dir("c:\new.txt") = "" Then
Open "c:\new.txt" For Output As #1
Close #1
End If
Open "c:\New.Txt" For Append As #1
Print #1, n
Close #1
End Sub


I think it has got something to do whith the binary output.
 
Oh, found the real problem. Your var n is a variant it should be dimentiond as string, like so:

Private Sub Command1_Click()
Dim n As String

n = (Chr(13) & Chr(10) & "*****" & Chr(13) & Chr(10) & "Monday 15 July 2001" & Chr(13) & Chr(10) & "Testing This" & Chr(13) & Chr(10) & "Hope it works")
Open "c:\New.Txt" For Binary As #1
Put #1, LOF(1) + 1, n
Close #1
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top