Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Writing to a file (.dat)

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,149
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Writing to a file (.dat)
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Writing to a file (.dat) - 6/10/2001 10:32:53 AM   
  jordan

 

Posts: 9
Score: 0
Joined: 6/9/2001
From: USA
Status: offline
I have the following code to write a filename (which is passed from
elsewhere) to the top line (I guess by making a new line) of a dat
file leaving the rest of its contents untouched. This code puts the
filename there but seems just to be making a new file as the
contents of the original file dissapear.

Function WriteLineToFile(filename)
Const ForReading = 1, ForWriting = 2
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(DATA_PATH & filename, ForWriting,
False)
f.WriteLine filename
End Function

Can you help?
 
 
Post #: 1
 
 Re: Writing to a file (.dat) - 6/10/2001 10:33:56 AM   
  mid

 

Posts: 16
Score: 0
Joined: 6/4/2001
From: USA
Status: offline
You are opening for writing - you should open for
Read AND Write if you wish to conserve the contents of the file. I
have not checked but I guess it is 3...

(in reply to jordan)
 
 
Post #: 2
 
 RE: Re: Writing to a file (.dat) - 3/30/2006 8:48:32 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Old question but I wanted to put in the correct answer so searchers would find it. The file needs to be open for Appending which is a constant of 8. SO:

Function WriteLineToFile(filename)
   Const ForReading = 1
   Const ForWriting = 2
    Const ForAppending = 8
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.OpenTextFile(DATA_PATH & filename, ForAppending, False)
   f.WriteLine filename
End Function

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to mid)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Writing to a file (.dat) Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts