Appending to text file? 
Author Message
 Appending to text file?

I need help!!! I am not able to append to this file i am creating. This is a
log file but everytime i run it, it overwrites the contents of the file.
Here is the code:

const ForWriting = 2
const ForReading = 1
const ForAppending = 8
Dim oFA

 set oFA = wscript.createObject("scripting.filesystemobject")
 oFA.createtextfile user & ".txt"
 file =  user & ".txt"
 set f = oFA.opentextfile (file, ForAppending, false)
 f.write "USERNAME= " & user & " I.P = "& address & " TiME= " & Date & "
WORKSTATION= " & computer & chr(10) & chr(13)
 f.close
 Set oFA = nothing

Thanks!!!



Sun, 16 Nov 2003 00:56:27 GMT  
 Appending to text file?
Erla,

Try this:

Dim objFSO, FilePointer, TheFileName
set objFSO= CreateObject("Scripting.FileSystemObject")

TheFileName = user & ".txt"
' This will create the file if it does not exist.
If objFSO.FileExists(TheFileName) then
      set FilePointer = objFSO.CreateTextFile(TheFileName, True)
      FilePointer.Close
End If

'Otherwise you will open the file just for appending to it
Set FilePointer = objFSO.OpenTextFile(TheFileName, ForAppending)
FilePointer.WriteLine("USERNAME= " & user & " I.P = "& address & " TIME= " &
Date & "WORKSTATION= " & computer)
FilePointer.Close

set objFSO = Nothing
---
Note that you will need to include methods from the wscript.shell object in
order to obtain the IP address of the
machine where the user is working.



Quote:
> I need help!!! I am not able to append to this file i am creating. This is
a
> log file but everytime i run it, it overwrites the contents of the file.
> Here is the code:

> const ForWriting = 2
> const ForReading = 1
> const ForAppending = 8
> Dim oFA

>  set oFA = wscript.createObject("scripting.filesystemobject")
>  oFA.createtextfile user & ".txt"
>  file =  user & ".txt"
>  set f = oFA.opentextfile (file, ForAppending, false)
>  f.write "USERNAME= " & user & " I.P = "& address & " TiME= " & Date & "
> WORKSTATION= " & computer & chr(10) & chr(13)
>  f.close
>  Set oFA = nothing

> Thanks!!!



Sun, 16 Nov 2003 05:24:41 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Append to text file

2. Append a text file

3. Appending 2 text files

4. Appending from Text file to mdb

5. Appending a text file

6. How do you append to text files together in VB

7. How do you append to text files together in VB

8. appending a text file

9. Appending to text file?

10. appending a text file

11. Append to text file

12. Reading/Appending a Text file. Comma delimited

 

 
Powered by phpBB® Forum Software